import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { NavController, MenuController, ModalController, LoadingController, Platform, IonRefresher } from '@ionic/angular';
import { Storage } from '@ionic/storage';
import { HttpService } from 'src/app/service/http.service';
import { UrlService } from 'src/app/service/url.service';
import { ToolService } from 'src/app/service/tool.service';
import { ActivatedRoute, Params } from '@angular/router';
import { ConfigService } from 'src/app/service/config.service';
import { PopwinService } from 'src/app/service/popwin.service';
import { EventService } from 'src/app/service/event.service';
import * as $ from 'jquery';
import { NativeAudio } from '@ionic-native/native-audio/ngx';
import { BetComponent } from '../bet/bet.component';



@Component({
  selector: 'app-lotdetail',
  templateUrl: './lotdetail.page.html',
  styleUrls: ['./lotdetail.page.scss'],
})
export class LotdetailPage implements OnInit, OnDestroy {
  public code: string; //类型的code码标识
  public isDiffCode: boolean = true; //当前和上一次是否相同，true为不相同
  public lotName: string = "出彩结果";
  public resHeight;//出奖结果的第一条数据的默认高度
  public close_time;//单独显示出奖结果的第一条
  public lotRes: any[];
  public lotResLength: number = 0;//长度
  public tabarData = { "cycleid": "", "sdate": "", "balls": "", "sum": "", "nn": "", "dx": "", "ds": "", "gylh": "", "show": "", "tm": "", "zh": "","bsl":"" };
  public showStateData = {};
  public listData = [];
  public isRes = false;
  public lotTimer: any = { "cycleid": '', "isclosed": '', "countdown": '' };//出彩结果的第一条数据
  public lotFirstMsg: string = ""; //出彩结果第一条的文字
  public playMenu: any[];//玩法的菜单
  public lotNumData: any[];//盘口的数据
  public tablebar: any[];//盘口的tablebar的切换
  public isLotRes: boolean = false;
  public lotMark: string = ""; //显示的数据的地方
  private clickMark = 0; //互斥选择左边的菜单
  public playCode: string;//玩法的code标识
  public showLotClickMarkState = 0;
  public selectLotNumber = 0;//选择了多少个倍率
  public betMoney;//输入投资的金额input
  private selectLotNumberArr: any[];//选择倍率的数据，拼接成数值
  private timerObj: any;//计时器的对象
  private timerObjArr = [];
  private tempTimer01;
  private tempTimer01Arr = [];
  private tempTimer02;
  private tempTimer02Arr = [];
  private tempTimer03;//自动刷新盘口的计时器
  private tempTimer03Arr = [];
  private tempTimer04;//第一次进入刷开奖的计时器
  private tempTimer04Arr = [];
  private firstNum = 0;//加值最新5期的最新一期的期数
  private isFirstNum = false; //第一个id是否获取
  private secondNum = 0;//加载最新一期的期数
  private isSecondNum = false;//第二个是id是否获取
  private lotteryId;//彩种大类的id
  public playABCD = "";//ABCD盘
  public regionArr: any[] = [];//ABCD盘的数据
  public regionNum = 1;//ABCD盘的数量
  public isRegion: boolean = false;//是否显示模板中的
  public isMoney: boolean = false;//是否显示余额
  public moneyObj: any = { "credit2": 0, "credit_expend3": 0, "total": 0, "today": 0 };//余额的对象
  public clientHeight;
  private refreshResCount = 0;//刷新开奖结果的次数
  private selectPlayItemData;//选择玩法存储的数据
  public disableBet = false;//是否禁止下注
  public fast = true;  //默认是快速投注的效果
  public fastShowState = false;//快速投资的地板面板默认隐藏
  public betTotalMoney: any = 0;//计算的总投资额
  private betInputVal: any = 0;//投资的input的输入值
  public isResOrFastmoney: boolean = false;//false是金额页，true是结果
  public isMarkWin: boolean = false; //蒙版窗口的显示或隐藏
  private fastDefaultMoneyList: any = { "o": 50, "t": 100, "th": 200, "f": 500, "fi": 1000 };
  public fastMoneyList: any = { "o": 50, "t": 100, "th": 200, "f": 500, "fi": 1000 };
  public betSuccessObj: any; //投注成功后的数据回显
  private mixRateSelect: any[] = [];//快捷玩法的赔率
  private mixType: any[] = [];//快捷玩法选择类别的的赔率id存储的数值
  private mixBetArr: any[] = [];//类型和赔率最后需要提交的值的综合
  public specialRateVal: any = 0;//合肖和自选不中的值
  public specialZmlmTypeLotColLock = 0; //连码的下标标记
  private specialZmlmTypeLotColItem: any;//连码的第一条数据
  private selectZmlmNum = 1;//连码的选中个数
  private selectZmlmArr: any = [];//选中连码的数组
  private specialData: any = [];
  private f3dLotData: any = [];//福彩3d存储的数据
  private f3dzx3_zx6: any = [];//福彩3d的组选3和组选6的的一条数据

  public isShowTab = true; //是否显示底部的tab
  public isShowFastDragonTiger = true;//是否显示快捷投注玩法中的龙虎

  public lotMenuArr: any[] = []; //下拉的菜单数据
  public lotMenuTimerArr: any[] = [];//下拉下来的菜单的计时器数组
  public lotMenuTimeTen: any[] = [];//每隔十秒刷新菜单的时间

  //2019-12-5增加新的长龙的玩法
  public clArr: any[] = [];//长龙的数据
  public isCl: boolean = false;
  public periodValue = "6";//选中的期数
  private periodPreValue = "6";
  private periodTimerArr = [];//存储计时器防止重复加快计时
  private clTenTimerArr = [];//长龙间隔10s加载的计时器
  private selectClItemArr = [];//手动长龙选中的值存储

  constructor(private navCtrl: NavController, private menu: MenuController, private http: HttpService, private activatedRoute: ActivatedRoute, private popWin: PopwinService, private eventS: EventService,
    private nativeAudio: NativeAudio, private modalCtrl: ModalController, private store: Storage, private loadingCtrl: LoadingController, private platform: Platform) {
    this.clientHeight = ($(window).height() - 218) + "px";
    let that = this;
    this.activatedRoute.queryParams.subscribe((params: Params) => {
      let tempDeal = JSON.parse(ToolService.paramAESDecrypt(params['p']));
      that.code = tempDeal['code'];
      that.lotName = tempDeal['name'];
      that.lotteryId = tempDeal['lotteryId'];
      that.getDiffCodeState();//获取是否上一次和本次彩种相同
      $("app-root").attr("code", that.code).attr("name", that.lotName).attr("lotteryId", that.lotteryId);
    });

    this.clearPeriodTimer();//清除长龙的计时器
    this.clearCLTenTimer();
  }

  ngOnInit() {
    // let that = this;
    // let storeData;
    // await this.store.get(ConfigService.PLAYER_KEY + that.code).then(function (data) {
    //   storeData = data;
    // });
    // if (!ToolService.isEmpty(storeData)) {

    //   this.popWin.toast("价值");
    // }
    this.eventS.publish("indexClearTimeOut");
    this.clearTimer(this.timerObjArr);
    this.clearTimer(this.tempTimer03Arr);
    this.initEvent();
    this.updataLotCount();
    this.playNetData();
    this.fast = this.isFastFun();//是否显示快速投注的方式
    //获取底部的默认的投资金额
    let tempfastMoneyList = localStorage.getItem("fastMoneyList");
    if (!ToolService.isEmpty(tempfastMoneyList) && ToolService.isStringJSON(tempfastMoneyList)) {
      this.fastMoneyList = JSON.parse(tempfastMoneyList);
    } else {
      this.fastMoneyList = this.fastDefaultMoneyList;
    }
    this.getLotResStore(); //缓存的前5期数据
    if (this.platform.is("android")) {
      this.lotResNet(5);
      this.refreshLastTime();
      this.enterRefreshLotRes();
      this.getMoney();
    }
    this.initSoundImg();
    this.deailPresetVal();
  }
  ionViewDidEnter() {
    // let that = this;
    // let storeData;
    // await this.store.get(ConfigService.PLAYER_KEY + that.code).then(function (data) {
    //   storeData = data;
    // });
    // if (ToolService.isEmpty(storeData)) {
    //   that.loadData();
    // }
    if (!this.platform.is("android")) {
      this.lotResNet(5);
      this.refreshLastTime();
      this.enterRefreshLotRes();
      this.getMoney();
    }

  }
  enterRefreshLotRes() {
    let that = this;
    that.clearTimer(that.tempTimer04Arr);
    that.tempTimer04 = setInterval(function () {
      if (that.isFirstNum && that.isSecondNum) {
        clearInterval(that.tempTimer04);
        if (that.isEnterPageRefreshRes(that.firstNum, that.secondNum)) {
          that.refreshLastRes();
        }
      }
    }, 1000);
    that.tempTimer04Arr.push(that.tempTimer04);
  }
  loadData() {
    let that = this;
    this.lotResNet(5);
    this.initEvent();
    this.playNetData();
    this.updataLotCount();
    //清除首页的倒计时时间
    this.eventS.publish("indexClearTimeOut");
    this.getMoney();
  }
  /**
   * 返回上一页
   */
  backClick() {
    this.navCtrl.navigateBack("/");
    //开启首页的每隔10s请求一次时间
    //  this.eventS.publish("indexStartTime");
    this.hideRegionAndMoney();
    this.fastShowState = false;
    this.clearAllTime();
    this.hideDownMenu();

  }
  /**
   * 抽屉菜单
   */
  toLotMenuPage() {
    // this.menu.enable(true, 'lotMenu');
    // this.menu.open('lotMenu');
    $(".lotMenu").css("display", "block");
    this.eventS.publish("getMenuUserinfo");
    this.eventS.publish("indexClearTimeOut");
    this.eventS.publish("getSlideMenu", false);
  }
  /**
   * 侧滑菜单的触发事件
   */
  initEvent() {
    let that = this;
    this.eventS.subscribe("menuEvent", function (code, name, lotteryId) {
      if (that.lotName != name) {
        that.code = code;
        that.lotName = name;
        that.clearTimer(that.timerObjArr);
        that.clearTimer(that.tempTimer02Arr, true);
        that.clearTimer(that.tempTimer03Arr);
        that.isFirstNum = false;
        that.isSecondNum = false;
        that.getLotResStore();
        that.lotResNet(5); //
        that.updataLotCount();
        that.refreshLastTime();
        that.enterRefreshLotRes();
        that.playMenu = [];
        that.lotNumData = [];
        that.playNetData();
        that.hideRegionAndMoney();
        that.getDiffCodeState();
        $("app-root").attr("code", code).attr("name", name).attr("lotteryId", lotteryId);
      }
    }, true);
    //第一个是选中的状态
  }
  doRefresh(event) {
    setTimeout(() => {
      event.target.complete();
    }, 2000);
  }

  countTime() {
    let that = this;
    that.clearTimer(this.timerObjArr);
    let temp = this.lotTimer.close_time;
    let temp1 = this.lotTimer.lfopentime; //开盘时间
    let tempObj = $(".lot-first-time");
    this.timerObj = setInterval(function () {
      if (temp >= 0) {
        that.lotFirstMsg = "截止";
        that.disableBet = false;
        if (temp == 0) {
          that.close_time = "";
        } else {
          that.close_time = temp;
        }
        // tempObj.html(ToolService.formateTime(temp, true));
      } else if (temp < 0 && temp1 >= 0) {
        that.lotFirstMsg = "封盘中";
        that.disableBet = true;
        that.close_time = temp1;
        // tempObj.html(ToolService.formateTime(temp1, true));
      }
      temp--;
      temp1--;
      if (temp1 == -1) {
        that.refreshLastTime();
        that.refreshLastRes();
        clearInterval(this.timerObj);
        this.timerObj = null;
      }
    }, 1000);
    this.timerObjArr.push(this.timerObj);
  }

  //清除计时器，并清空数据
  clearTimer(timer, isTimeOut?: boolean) {
    if (timer.length > 0) {
      for (let i = 0; i < timer.length; i++) {
        if (isTimeOut) {
          clearTimeout(timer[i]);
        } else {
          clearInterval(timer[i]);
        }
        timer[i] = null;
      }
    }
  }
  ngOnDestroy() {
    this.clearAllTime();
  }
  clearAllTime() {
    this.clearTimer(this.timerObjArr);
    this.timerObjArr = [];
    this.clearTimer(this.tempTimer01Arr, true);
    this.tempTimer01Arr = [];
    this.clearTimer(this.tempTimer02Arr, true);
    this.tempTimer02Arr = [];
    this.clearTimer(this.tempTimer03Arr);
    this.tempTimer03Arr = [];
    this.clearTimer(this.tempTimer04Arr);
    this.tempTimer04Arr = [];
    //清除长龙的计时器
    this.clearCLTenTimer();
    this.clearPeriodTimer();
  }
  playSound() {
    let that = this;
    this.store.get(ConfigService.LOT_SOUND).then((data) => {
      if (data == 1 || data == '1') {
        return;
      } else {
        that.nativeAudio.preloadSimple('uniqueId1', 'assets/mp3/kaijiang.mp3');
        that.nativeAudio.play('uniqueId1');
      }
    });
  }
  initSoundImg() {
    this.store.get(ConfigService.LOT_SOUND).then((data) => {
      if (data == 1 || data == '1') {
        $(".res-fun-change-v .iconfont").removeClass("ion-ios-shengyin").addClass("ion-ios-jingyin");
      } else {
        $(".res-fun-change-v .iconfont").removeClass("ion-ios-jingyin").addClass("ion-ios-shengyin");
      }
    });
  }
  //隐藏声音的操作
  stopSound() {
    let that = this;
    this.store.get(ConfigService.LOT_SOUND).then((data) => {
      if (data == 1 || data == '1') {
        that.store.set(ConfigService.LOT_SOUND, 0);
        $(".res-fun-change-v .iconfont").removeClass("ion-ios-jingyin").addClass("ion-ios-shengyin");
      } else {
        that.store.set(ConfigService.LOT_SOUND, 1);
        $(".res-fun-change-v .iconfont").removeClass("ion-ios-shengyin").addClass("ion-ios-jingyin");
      }
    });
  }
  /**
   * 加载近5期开奖结果
   * @param type 1为最新一条数据，5为最新5条数据
   */
  lotResNet(type) {
    let that = this;
    let obj = "{\"topcode\":\"" + that.code + "\",\"type\":\"" + type + "\"}";
    console.log(obj);
    this.http.get(UrlService.LOTTERY_OPENLOTTERY, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(resD => {
      let data = resD.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        that.lot20Data(that.code);
        that.clearTimer(that.tempTimer01Arr, true);
        console.log("开奖", ToolService.aesDecodeToJson(data.data));
        let tempData = ToolService.aesDecodeToJson(data.data);
        let res = tempData.data;
        if (ToolService.isEmpty(res)) {
          that.popWin.toast("暂无开奖记录");
          return;
        }
        that.isFirstNum = true;
        if (res.length > 0) {
          that.firstNum = res[0]['cycleid'];
        }
        console.log("近5期:", res);
        if (!ToolService.isEmpty(res) && res.length > 0) {
          that.lotRes = res;
          that.isLotRes = true;
          that.clientHeight = ($(window).height() - 218) + "px";
          that.resHeight = "90px";
          that.store.set("lotRes_" + that.code, res);//将近5期的开奖结果给存起来
        }
      } else {
        that.clientHeight = ($(window).height() - 218) + "px";
        that.isLotRes = false;
      }
    }, error => {
      // this.popWin.toast(ToolService.newError(error));
    });
  }
  //获取存储的5最新5期数据
  async getLotResStore() {
    let that = this;
    let storeData;
    await this.store.get("lotRes_" + that.code).then(function (data) {
      storeData = data;
    });
    if (!ToolService.isEmpty(storeData)) {
      that.isLotRes = true;
      that.lotRes = storeData;
      that.clientHeight = ($(window).height() - 218) + "px";
      that.resHeight = "90px";
    }
  }
  /**
   * 加载出奖结果--从接口来读取数据
   */
  lotResNetBark() {
    let that = this;
    let obj = "{\"code\":\"" + that.code + "\"}";
    console.log(obj);
    this.http.get(UrlService.USER_GAMSYS, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        that.clearTimer(that.tempTimer01Arr, true);
        console.log("开奖", ToolService.aesDecodeToJson(data.data));
        let tempData = ToolService.aesDecodeToJson(data.data);
        let res = tempData.data;
        if (res.length > 0) {
          if (that.firstNum == 0) {
            that.firstNum = res[0]['cycleid'];
          }
        }
        that.lotTimer = tempData.next;
        console.log("被动加载时间:", that.lotTimer);
        let temp = that.lotTimer.close_time;
        if (temp >= 0) {
          that.lotFirstMsg = "截止";
          that.disableBet = false;
          that.close_time = that.lotTimer.close_time;
        } else if (temp < 0 && that.lotTimer.lfopentime > 0) {
          that.lotFirstMsg = "封盘中";
          that.disableBet = true;
          that.close_time = that.lotTimer.lfopentime;
        }
        console.log(that.lotTimer);
        console.log("近5期:", res);
        if (!ToolService.isEmpty(res)) {
          that.lotRes = res;
          that.isLotRes = true;
          that.clientHeight = ($(window).height() - 218) + "px";
          that.resHeight = "80px";
          if (that.code == 'ssn' || that.code == 'xyssc' || that.code == 'ssh' || that.code == 'ss8' || that.code == 'sgs' || that.code == 'f3d' || that.code == 'pl3' || that.code == 'ssc' || that.code == 's3s' || that.code == 'js3' || that.code == 'sg3' || that.code == 'stj') {
            that.resHeight = "88px";
          }
          that.tempTimer01 = setTimeout(function () {
            clearTimeout(that.tempTimer01);
            that.countTime();
          }, 10);
          that.tempTimer01Arr.push(that.tempTimer01);
        }
      } else {
        that.clientHeight = ($(window).height() - 218) + "px";
        that.isLotRes = false;
      }
    }, error => {
      // this.popWin.toast(ToolService.newError(error));
    });
  }
  /**
   * 加载最新一期的结果
   */
  refreshLastRes() {
    let that = this;
    let obj = "{\"topcode\":\"" + that.code + "\",\"type\":\"1\"}";
    this.http.get(UrlService.LOTTERY_OPENLOTTERY, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp);
        console.log("最新一期的数据", res);
        if (!ToolService.isEmpty(res)) {
          if (that.firstNum != res.cycleid) {
            that.playSound();
            that.firstNum = res.cycleid;
            that.lotRes.unshift(res);
            that.getMoney();//金额随着最新一次数据加载完成后更新
            /////////
          } else {
            that.clearTimer(that.tempTimer02Arr, true);
            clearTimeout(that.tempTimer02);
            that.tempTimer02 = null;
            that.tempTimer02 = setTimeout(function () {
              that.refreshLastRes();
              that.clearTimer(that.tempTimer02Arr, true);
              clearTimeout(that.tempTimer02);
              that.tempTimer02 = null;
            }, 1000);
            that.tempTimer02Arr.push(that.tempTimer02);
          }
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 进入页面判断是否进行开奖 
   * @param preCycleid 已经开出的最新一期id
   * @param nextCycleid 最新一期
   * ture未开奖刷新结果，false开机不刷新结果
   */
  isEnterPageRefreshRes(preCycleid, nextCycleid) {
    if (ToolService.isEmpty(preCycleid) || ToolService.isEmpty(nextCycleid) || preCycleid == 0 || nextCycleid == 0) {
      return;
    }
    let tempPre = parseInt(preCycleid.substr(-2, 2));
    let add = tempPre + 1;
    let tempPre01 = "" + add;
    if (add < 10) {
      tempPre01 = "0" + add;
    }
    let tempNext = nextCycleid.substr(-2, 2) + "";
    if (tempPre01.length >= 3) {
      if (tempPre01.substr(-2, 2) < tempNext) {
        return true;
      } else {
        return false;
      }
    } else {
      if (tempPre01 < tempNext) {
        return true;
      } else {
        return false;
      }
    }
  }
  /**
   * 刷新最近一期结果  --- 走的接口数据
   */
  refreshLastResBark() {
    let that = this;
    let obj = "{\"code\":\"" + that.code + "\"}";
    this.http.get(UrlService.USER_GAMSYONE, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let res = ToolService.aesDecodeToJson(temp).data;
        if (res.length > 0) {
          if (that.firstNum != res[0]['cycleid']) {
            that.playSound();
            that.firstNum = res[0]['cycleid'];
            that.lotRes.unshift(res[0]);
            // 重新处理开奖倒计时的问题
            let tempCloseTime = that.lotTimer.close_time - that.refreshResCount;
            let tempLfopentime = that.lotTimer.lfopentime - that.refreshResCount;
            // console.log("加载的次数:",that.refreshResCount,"原来:",that.lotTimer.close_time,"-xx:",tempCloseTime);
            that.clearTimer(that.tempTimer01Arr, true);
            that.tempTimer01 = setTimeout(function () {
              let temp = that.lotTimer.close_time - that.refreshResCount;
              if (temp >= 0) {
                that.lotFirstMsg = "截止";
                that.disableBet = false;
                that.close_time = tempCloseTime;
              } else if (temp < 0 && tempLfopentime > 0) {
                that.lotFirstMsg = "封盘中";
                that.disableBet = true;
                that.close_time = tempLfopentime;
              }
              clearTimeout(that.tempTimer01);
              that.countTime();
            }, 10);
            that.tempTimer01Arr.push(that.tempTimer01);
            that.refreshResCount = 0;//统计刷新最后一次结果的次数
            /////////
          } else {
            that.clearTimer(that.tempTimer02Arr, true);
            that.tempTimer02 = setTimeout(function () {
              clearTimeout(that.tempTimer02);
              that.refreshLastRes();
              that.refreshResCount++;
            }, 1000);
            that.tempTimer02Arr.push(that.tempTimer02);
          }
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 刷新当前结束时间
   */
  refreshLastTime() {
    let that = this;
    let obj = "{\"code\":\"" + that.code + "\"}";
    this.http.get(UrlService.USER_GAMSYSTIME, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp1 = data.data;
        let res = ToolService.aesDecodeToJson(temp1);
        that.lotTimer = res.next;
        that.secondNum = that.lotTimer.cycleid;
        that.isSecondNum = true;
        if ((that.lotTimer.isclosed == 1 && that.lotTimer.countdown == 0) || that.lotTimer.unusual == 1) {
          that.disableBet = true;
          that.lotFirstMsg = "";
          that.close_time = "";
          return;
        }
        let temp = that.lotTimer.close_time;
        if (temp >= 0) {
          that.lotFirstMsg = "截止";
          that.disableBet = false;
          that.close_time = that.lotTimer.close_time;
        } else if (temp < 0 && that.lotTimer.lfopentime > 0) {
          that.lotFirstMsg = "封盘中";
          that.disableBet = true;
          that.close_time = that.lotTimer.lfopentime;
        }
        console.log("自动刷新刷新的时间：", that.lotTimer);
        that.countTime();
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 选择ABCD盘时候的显示数据
   * @param ABCD 
   */
  showABCDLot(ABCD) {
    this.isRegion = false;
    let that = this;
    if (ToolService.isEmpty(ABCD)) {
      ABCD = "A";
    }
    let obj = "{\"toplotid\":\"" + that.lotteryId + "\",\"region\":\"" + ABCD + "\"}";
    this.http.get(UrlService.USER_EDITREGION, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        that.playABCD = ABCD;
        that.updatePlayRegionData(ABCD);
        if (that.playMenu.length > 0) {
          that.showLotData(that.playMenu[that.clickMark], that.clickMark, true);
          that.setPlayClickMark(that.clickMark);
          that.playMenu[that.clickMark].isActive = true;
        }
      } else if (data.code == ConfigService.FAIL_CODE) {
        this.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        this.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  //显示隐藏选择的切换ABCD盘的div
  changeRegion() {
    this.isRegion = !this.isRegion;
    this.isMoney = false;
  }
  showMixPlay(data) {
    let that = this;
    //有玩法
    if (that.code == 'pks' || that.code == 'pka' || that.code == 'yka' || that.code == 'sg8' || that.code == 'pt8' || that.code == 'pk8' || that.code == 'pkt' || that.code == 'sjs' || that.code == 'yjs' || that.code == 'ss8' || that.code == 'sgs' ||
      this.code == 'ssn' || this.code == 'xyssc' || this.code == 'ssc' || this.code == 'ssg' || this.code == 'klsf' || this.code == 'az8' || this.code == 'yz8' || this.code == 's10' || this.code == 'sgx' || this.code == 'sxg' || this.code == 'jsg' || this.code == 'sx5') {
      let kj = { "code": "fast", "title": "快捷" };
      if (data.lotsMenu.length > 0) {
        if (data.lotsMenu[0]['code'] == 'fast') {
          that.playMenu = data.lotsMenu;
          this.playMenu[0].isActive = false;
        } else {
          that.playMenu = data.lotsMenu;
          that.playMenu.unshift(kj);
        }
        if (ToolService.isEmpty($("app-root").attr("playMark"))) {
          that.initSelectPlay(1);
        } else {
          if (!that.isDiffCode) {
            that.initSelectPlay($("app-root").attr("playMark"));
          } else {
            that.initSelectPlay(1);
          }

        }
      }
    } else {
      that.playMenu = data.lotsMenu;
      if (that.playMenu.length > 0) {
        if (ToolService.isEmpty($("app-root").attr("playMark"))) {
          that.initSelectPlay(0);
        } else {
          if (!that.isDiffCode) {
            that.initSelectPlay($("app-root").attr("playMark"));
          } else {
            that.initSelectPlay(0);
          }
        }
      }
    }
    //添加长龙玩法play的入口数据
    if (that.code == 'pks' || that.code == 'pka' || that.code == 'yka' || that.code == 'ssc' || that.code == 'ss8' || that.code == 'sgs' || that.code == 'sjs' || that.code == 'yjs' || that.code == 'pk8' || that.code == 'pt8' || that.code == 'pkt' || that.code == 'f3d' || that.code == 'pl3' || that.code == 'ssn' || that.code == 'sgx' || that.code == 'sxg' || that.code == 'jsg' || that.code == 'sx5' || that.code == 's3s' || that.code == 'js3' || that.code == 'sg3' || that.code == 'sg8' || that.code == 'xyssc' || that.code == 'ssn' || that.code == 'ssg' || that.code == 'klsf' || that.code == 'az8' || that.code == 'yz8' || that.code == 's10') {
      that.playMenu.push({ "code": "cl", "title": "长龙" });
    }

  }
  getDiffCodeState() {
    if ($("app-root").attr("code") == this.code && !ToolService.isEmpty($("app-root").attr("code"))) {
      this.isDiffCode = false;
    } else {
      this.isDiffCode = true;
    }
  }
  initSelectPlay(index) {
    this.showLotData(this.playMenu[index], index, true);
    this.playMenu[index].isActive = true;
    this.setPlayClickMark(index);
  }
  /**
   * 玩法菜单的数据显示
   */
  playNetData() {
    let that = this;
    this.store.get(ConfigService.PLAYER_KEY + that.code).then(function (data) {
      if (ToolService.isEmpty(data)) {
        that.playNet();
        return;
      }
      that.playABCD = data.region;
      that.regionNum = data.regions_cnt;
      let regions2 = data.regions2;
      that.showMixPlay(data);
      that.regionArr = [];
      for (let item in regions2) {
        that.regionArr.push({ 'key': item, 'name': regions2[item] });
      }
    });
  }
  /**
   * 更新缓存玩法中的盘口的值
   * @param playABCD 
   */
  updatePlayRegionData(playABCD) {
    let that = this;
    this.store.get(ConfigService.PLAYER_KEY + that.code).then(function (data) {
      if (ToolService.isEmpty(data)) {
        return;
      }
      data.region = playABCD;
      that.store.set(ConfigService.PLAYER_KEY + that.code, data);
    });
  }

  playNet() {
    let that = this;
    let obj = "{\"toplotcode\":\"" + that.code + "\"}";
    this.http.get(UrlService.USER_PLAY, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let tempData = ToolService.aesDecodeToJson(data.data);
        that.store.set(ConfigService.PLAYER_KEY + that.code, tempData).then(function () {
          that.showMixPlay(tempData);
          that.playABCD = tempData.region;
          that.regionNum = tempData.regions_cnt;
          let regions2 = tempData.regions2;
          that.regionArr = [];
          for (let item in regions2) {
            that.regionArr.push({ 'key': item, 'name': regions2[item] });
          }
        });
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      }
    }, error => {
      // this.popWin.toast(ToolService.newError(error));
    });
  }
  /**
   * 选择左边的菜单
   * @param mark 
   */
  activeShow(mark) {
    this.hideRegionAndMoney();
    $(".lot-left-menu-row ion-col").removeClass("active");
    $(".lot-left-menu-row ion-col").eq(mark).addClass("active");
    this.clientHeight = ($(window).height() - 218) + "px";
  }
  /**
   * 玩法的数据的加载
   * @param playCode 玩法的code
   */
  showLotNet(playCode, realPlayCode) {
    let that = this;
    that.store.get(ConfigService.RATE_KEY + that.code + that.playABCD).then(function (d) {
      console.log("赔率文件的所有数据:", d);
      if (ToolService.isEmpty(d)) {
        let param = "{\"topcode\":\"" + that.code + "\",\"region\":\"" + that.playABCD + "\"}";
        console.log("点击玩法的加载参数:", param);
        that.http.get(UrlService.LOTTERY_GETODDS, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(param) }).subscribe(res => {
          let data = res.json();
          ToolService.setEncrypt(data.encrypt);
          if (data.code == ConfigService.SUCCESS_CODE) {
            // let tempRes = ToolService.aesDecodeToJson(data.data); //有加密的解密
            let tempRes = data.data;
            that.store.set(ConfigService.RATE_KEY + that.code + that.playABCD, tempRes)
            let tempData = tempRes[playCode];
            if (playCode == 'qlc_zmlm' || playCode == 'lhc_zmlm' || playCode == 'mlc_zmlm' || playCode == 'twd_zmlm') {//六合彩中的连码特殊处理
              tempData['item'][0]['list'] = that.specialZmlm(tempData['item'][0]['list']);
              that.specialZmlmTypeLotColItem = tempData['item'][0]['list'][0];
            } else if (playCode == 'ssg_rx' || playCode == 'sxg_rx' || playCode == 'jsg_rx' || playCode == 'sx5_rx' || playCode == 'klsf_rx' || playCode == 'az8_rx' || playCode == 'yz8_rx' || playCode == 's10_rx' || playCode == 'stj_rx') {//广东快乐十分,天津快乐十分,澳洲幸运8,广东11选5
              that.specialZmlmTypeLotColItem = tempData['item'][0]['list'][0];
            } else if (playCode == 'qlc_ddb' || playCode == 'lhc_ddb' || playCode == 'mlc_ddb' || playCode == 'twd_ddb') { //六合彩中的连肖连尾
              that.specialZmlmTypeLotColItem = tempData.tablebar[0];
            } else if (playCode == 'ss8_zs3' || playCode == 'sgs_zs3') {//极速时时彩组选三
              that.specialZmlmTypeLotColItem = tempData['item'][0]['list'][0];
            }
            that.playCode = realPlayCode;
            if (!ToolService.isEmpty(tempData) && !ToolService.isEmpty(tempData.item) && Object.keys(tempData.item).length > 0) {
              if (playCode == "s3s_qt" || playCode == 'js3_qt' || playCode == 'sg3_qt') {
                that.lotNumData = that.s3s_qtDeail(tempData.item);
              } else if (playCode == "f3d_2dw" || playCode == 'pl3_2dw') {//福彩3d,体彩3d的二字
                that.f3dLotData = tempData.item['Z1-Z2'];
                that.f3dLotData[0].mark = "Z1-Z2";
                that.lotNumData = that.f3dLotData;
              } else if (playCode == "f3d_3dw" || playCode == 'pl3_3dw') {//福彩3d,体彩3d的三字
                that.f3dLotData = tempData.item;
                that.lotNumData = tempData.item;
              } else if (playCode == 'f3d_zs3' || playCode == 'f3d_zs6' || playCode == 's3s_zs3' || playCode == 's3s_zs6' || playCode == 'js3_zs3' || playCode == 'js3_zs6' || playCode == 'sg3_zs3' || playCode == 'sg3_zs6' || playCode == 'pl3_zs3' || playCode == 'pl3_zs6') {//福彩3d,体彩p3的组选3或组选6,江苏快三红码组合或黑码组合
                let temp: any[] = tempData.item;
                if (temp.length >= 2) {//限定以防止福彩3d的组选3或组选6报错
                  that.f3dzx3_zx6 = temp.shift();
                  that.lotNumData = temp;
                } else {
                  that.lotNumData = tempData.item;
                }
              } else {
                that.lotNumData = tempData.item;
              }
            } else {
              that.lotNumData = [];
            }
            if (!ToolService.isEmpty(tempData.tablebar) && tempData.tablebar.length > 0) {
              that.tablebar = tempData.tablebar;
            } else {
              that.tablebar = [];
            }
            if (that.tablebar.length > 0) {
              if (ToolService.isExitKey(that.tablebar[0], "name")) {
                that.tablebar[0]['isActive'] = true;
              }
              $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
            } else {
              $(".lot-tabbar ul").css({ "height": '0px' });
            }
          } else if (data.code == ConfigService.FAIL_CODE) {
            that.popWin.toast(data.message);
          } else if (data.code == ConfigService.LOGIN_CODE) {
            that.navCtrl.navigateForward("/login");
          }
        }, error => {
          console.log("error", error);
        });
        return;
      }
      //有倍率
      let tempData = d[playCode];
      if (playCode == 'qlc_zmlm' || playCode == 'lhc_zmlm' || playCode == 'mlc_zmlm' || playCode == 'twd_zmlm') {//六合彩中的连码特殊处理
        tempData['item'][0]['list'] = that.specialZmlm(tempData['item'][0]['list']);
        that.specialZmlmTypeLotColItem = tempData['item'][0]['list'][0];
      } else if (playCode == 'ssg_rx' || playCode == 'sxg_rx' || playCode == 'jsg_rx' || playCode == 'sx5_rx' || playCode == 'klsf_rx' || playCode == 'az8_rx' || playCode == 'yz8_rx' || playCode == 's10_rx' || playCode == 'stj_rx') {//广东快乐十分,天津快乐十分,澳洲幸运8
        that.specialZmlmTypeLotColItem = tempData['item'][0]['list'][0];
      } else if (playCode == 'qlc_ddb' || playCode == 'lhc_ddb' || playCode == 'mlc_ddb' || playCode == 'twd_ddb') { //六合彩中的连肖连尾
        that.specialZmlmTypeLotColItem = tempData.tablebar[0];
      } else if (playCode == 'ss8_zs3' || playCode == 'sgs_zs3') {//极速时时彩组选三
        that.specialZmlmTypeLotColItem = tempData['item'][0]['list'][0];
      }
      that.playCode = realPlayCode;
      if (!ToolService.isEmpty(tempData) && !ToolService.isEmpty(tempData.item) && Object.keys(tempData.item).length > 0) {
        if (playCode == "s3s_qt" || playCode == "js3_qt" || playCode == "sg3_qt") {
          that.lotNumData = that.s3s_qtDeail(tempData.item);
        } else if (playCode == "f3d_2dw" || playCode == 'pl3_2dw') {//福彩3d,体彩3d的二字
          that.f3dLotData = tempData.item['Z1-Z2'];
          that.lotNumData = that.f3dLotData;
          that.f3dLotData[0].mark = "Z1-Z2";
        } else if (playCode == "f3d_3dw" || playCode == 'pl3_3dw') {//福彩3d,体彩3d的三字
          that.f3dLotData = tempData.item;
          that.lotNumData = tempData.item;
        } else if (playCode == 'f3d_zs3' || playCode == 'f3d_zs6' || playCode == 's3s_zs3' || playCode == 's3s_zs6' || playCode == 'js3_zs3' || playCode == 'js3_zs6' || playCode == 'sg3_zs3' || playCode == 'sg3_zs6' || playCode == 'pl3_zs3' || playCode == 'pl3_zs6') {//福彩3d,体彩p3的组选3或组选6,江苏快三红码组合或黑码组合
          let temp: any[] = tempData.item;
          if (temp.length >= 2) {//限定以防止福彩3d的组选3或组选6报错
            that.f3dzx3_zx6 = temp.shift();
            that.lotNumData = temp;
          } else {
            that.lotNumData = tempData.item;
          }
        } else {
          that.lotNumData = tempData.item;
        }
      } else {
        that.lotNumData = [];
      }
      if (!ToolService.isEmpty(tempData) && !ToolService.isEmpty(tempData.tablebar) && tempData.tablebar.length > 0) {
        that.tablebar = tempData.tablebar;
      } else {
        that.tablebar = [];
      }
      if (that.tablebar.length > 0) {
        if (ToolService.isExitKey(that.tablebar[0], "name")) {
          that.tablebar[0]['isActive'] = true;
        }
        $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
      } else {
        $(".lot-tabbar ul").css({ "height": '0px' });
      }
      console.log("盘口", tempData);
    });
  }
  /**
   * 手动的去处理北京pk10的快捷的数据
   */
  getFastPks() {
    //pks_zp
    //pks_dw8
  }

  s3s_qtDeail(data) {//江苏快3 三军二字三字组合特殊的情况
    for (let item in data) {
      let list = data[item]['list'];
      for (let item01 in list) {
        data[item]['list'][item01]['ballsArr'] = list[item01]['balls'].toString().split("|");
      }
    }
    return data;
  }

  /**
   * 显示盘口的数据
   * @param data 
   * @param index 
   * @param isFirst 
   */
  showLotData(data: any, index: any, isFirst?: boolean) {
    this.selectPlayItemData = { "item": data, "index": index }
    if (this.clickMark == index) {
      if (!isFirst) {
        return;
      }
    }
    this.showLotClickMarkState = 0;
    this.onReset();
    //点击玩法重置一些变量
    this.resetVar();
    this.clickMark = index;
    this.activeShow(index);
    if (data.code == "cl") {//点击长龙的加载数据
      this.isCl = true;
      //加载网络数据
      this.resetSelectClItem();
      this.periodValue = "6";
      this.clearCLTenTimer();
      this.clearPeriodTimer();
      this.getClData();
      return;
    } else {
      this.isCl = false;
      this.clearCLTenTimer();
      this.clearPeriodTimer();
    }
    this.setPlayClickMark(index);//保存最后一次点击的位置
    let that = this;
    let lid = ToolService.isEmpty(data.lid) ? "" : data.lid;
    let code = ToolService.isEmpty(data.code) ? "" : data.code;
    if (code == 'fast' || code == 'qlc_zmlm' || code == 'lhc_zmlm' || code == 'mlc_zmlm' || code == 'twd_zmlm' || code == 'ssg_rx' || code == 'sxg_rx' || code == 'jsg_rx' || code == 'sx5_rx' || code == 'klsf_rx' || code == 'az8_rx' || code == 'yz8_rx' || code == 's10_rx' || code == 'stj_rx' || code == 'lhc_sxd' || code == 'mlc_sxd' || code == 'twd_sxd' || code == 'qlc_sxd' || code == 'lhc_slx' || code == 'mlc_slx' || code == 'twd_slx' || code == 'qlc_slx' || code == 'qlc_ddb' || code == 'lhc_ddb' || code == 'mlc_ddb' || code == 'twd_ddb' || code == 'f3d_2dw' || code == 'f3d_3dw'
      || code == 'f3d_zs3' || code == 'f3d_zs6' || code == 'pl3_2dw' || code == 'pl3_3dw' || code == 'pl3_zs3' || code == 'pl3_zs6' || code == 's3s_zs3' || code == 's3s_zs6' || code == 'js3_zs3' || code == 'js3_zs6' || code == 'sg3_zs3' || code == 'sg3_zs6' || code == 'ss8_zs3' || code == 'sgs_zs3') {  //强制底部弹出投资的方式
      this.fast = true;
    } else {
      this.fast = this.isFastFun();
    }
    console.log("玩法的data:", data);
    console.log("玩法code", code);
    let obj = "{\"code\":\"" + code + "\",\"lid\":\"" + lid + "\"}";
    console.log("显示盘口的参数值:", obj);
    if ((code == "ssg_dw8" && lid != "9") || (code == "klsf_dw8" && lid != "9") || (code == "az8_dw8" && lid != "9") || (code == "yz8_dw8" && lid != "9") || (code == "s10_dw8" && lid != "9") || (code == "stj_dw8" && lid != "9")) {
      this.showLotNet(code + lid, code);
    } else {
      this.showLotNet(code, code);
    }
    //福彩3d,体彩的二字定位和三字定位赔率获取

  }

  resetVar() {
    this.f3dLotData = [];
    this.specialZmlmTypeLotColItem = [];
    this.isShowFastDragonTiger = true;
  }
  /**
   * 显示盘口的数据--备份直接读取文件
   */
  showLotDataBarkfile(data: any, index: any, isFirst?: boolean) {
    if (this.clickMark == index) {
      if (!isFirst) {
        return;
      }
    }
    this.onReset();
    this.clickMark = index;
    this.activeShow(index);
    let that = this;
    let lid = ToolService.isEmpty(data.lid) ? "" : data.lid;
    let code = ToolService.isEmpty(data.code) ? "" : data.code;
    this.playCode = code;
    console.log("玩法code", code);

    let obj = "{\"code\":\"" + code + "\",\"lid\":\"" + lid + "\"}";
    console.log("显示盘口的参数值:", obj);

    that.store.get(ConfigService.RATE_KEY + that.code + that.playABCD).then(function (d) {
      if (ToolService.isEmpty(d)) {
        that.getJson(that.code, that.playABCD, function (fileData) {
          that.store.set(ConfigService.RATE_KEY + that.code + that.playABCD, fileData)
          let tempData = fileData[code];
          that.lotNumData = [];
          that.tablebar = [];
          that.lotNumData = tempData.item;
          that.tablebar = tempData.tablebar;
          if (that.tablebar.length > 0) {
            that.tablebar[0]['isActive'] = true;
            $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
          } else {
            $(".lot-tabbar ul").css({ "height": '0px' });
          }
          console.log("盘口", tempData);
        }, function () {
          that.popWin.toast("系统异常请重新登录");
        })
        return;
      }
      //有倍率
      let tempData = d[code];
      that.lotNumData = [];
      that.tablebar = [];
      that.lotNumData = tempData.item;
      that.tablebar = tempData.tablebar;
      if (that.tablebar.length > 0) {
        that.tablebar[0]['isActive'] = true;
        $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
      } else {
        $(".lot-tabbar ul").css({ "height": '0px' });
      }
      console.log("盘口", tempData);
    });
  }

  /**
   * 显示盘口的数据备份(通过网络请求的处理)
   * @param data 
   */
  showLotDataBark(data: any, index: any, isFirst?: boolean) {
    if (this.clickMark == index) {
      if (!isFirst) {
        return;
      }
    }
    this.onReset();
    this.clickMark = index;
    this.activeShow(index);
    let that = this;
    let lid = ToolService.isEmpty(data.lid) ? "" : data.lid;
    let code = ToolService.isEmpty(data.code) ? "" : data.code;
    this.playCode = code;
    console.log("玩法code", code);
    that.lotNumData = [];
    that.tablebar = [];
    let obj = "{\"code\":\"" + code + "\",\"lid\":\"" + lid + "\"}";
    console.log("显示盘口的参数值:", obj);
    this.http.get(UrlService.USER_SHOWLOTS, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let tempData = ToolService.aesDecodeToJson(data.data);
        that.lotNumData = tempData.item;
        that.tablebar = tempData.tablebar;
        if (that.tablebar.length > 0) {
          that.tablebar[0]['isActive'] = true;
          $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
        } else {
          $(".lot-tabbar ul").css({ "height": '0px' });
        }
        console.log("盘口", tempData);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  /**
  * 选择盘口开奖的的tab的处理逻辑
  * @param item  选择的一栏的数据
  * @param mark  下标
  */
  showLotBar(item, mark) {
    if (this.showLotClickMarkState != mark) {
      if (this.playCode == 'qlc_ddb' || this.playCode == 'lhc_ddb' || this.playCode == 'mlc_ddb' || this.playCode == 'twd_ddb') {
        this.specialZmlmTypeLotColItem = item;
        this.fastShowState = false;
      }
      this.showLotClickMarkState = mark;
      this.showLotBarData(item, mark);
      this.onReset();
    }
  }
  addMixType() {
    let sumCount = 0;
    let testArr = [];
    let mixArr = [];
    for (let itemF in this.mixType) {
      this.mixType[itemF] = [];
      mixArr.push(itemF);
      let index = 0;
      for (let item in this.mixRateSelect) {
        if (!ToolService.isEmpty(this.mixRateSelect[item]['item_id'][itemF])) {
          let temp = { "id": this.mixRateSelect[item]['item_id'][itemF], 'lotcode': this.mixRateSelect[item]['lotcode'], 'cash': 0 };
          this.mixType[itemF].push(temp);
          testArr.push(this.mixType[itemF][index]);
          sumCount++;
          index++;
        }
      }
    }
    if (testArr.length > 0) {
      this.fastShowState = true;
      this.deailPresetVal();
    } else {
      this.fastShowState = false;
    }
    if (this.code == 'klsf' || this.code == 'ssg' || this.code == 'az8' || this.code == 'yz8' || this.code == 's10') {
      this.fastExcludeDragonTiger(mixArr, 4);
    } else {
      this.fastExcludeDragonTiger(mixArr);
    }

    this.mixBetArr = testArr;
    this.selectLotNumber = sumCount;
    //计算投资总投资额
    this.calculateTotalBetMoney();
  }
  /**
   * 快捷tab的选择
   * @param mark 
   */
  showMixLotBar(mark) {
    if ($("#lot-mix-tabbar-" + mark).hasClass('active')) {
      $("#lot-mix-tabbar-" + mark).removeClass("active");
      delete this.mixType[mark];
    } else {
      $("#lot-mix-tabbar-" + mark).addClass("active");
      this.mixType[mark] = [];
    }
    this.addMixType();
  }
  /**
 * 快捷玩法的赔率的选中
 */
  selectMixLotCol(mark, item) {
    if (this.disableBet) {
      this.popWin.toast("已经处于封盘中");
      return;
    }
    let objStr = "#lot-mix-id-" + mark;
    if ($(objStr).hasClass('lot-select-col-active')) {
      $(objStr).removeClass("lot-select-col-active");
      delete this.mixRateSelect[mark];
    } else {
      $(objStr).addClass("lot-select-col-active");
      this.mixRateSelect[mark] = item;
    }
    this.addMixType();
  }
  /**
   * 快捷排除龙虎状态
   */
  fastExcludeDragonTiger(selectFastTab: any[], num = 5) {
    if (selectFastTab.length <= 0) {
      this.isShowFastDragonTiger = true;
      return;
    }
    for (let item in selectFastTab) {
      if (parseInt(selectFastTab[item]) < num) {
        this.isShowFastDragonTiger = true;
        return;
      }
    }
    $(".fast-lot-div-d").parents(".lot-select-col").removeClass("lot-select-col-active");
    this.isShowFastDragonTiger = false;
  }
  showLotBarData(item, mark) {
    let that = this;
    let obj = "{\"code\":\"" + that.playCode + "\",\"lid\":\"" + item.lid + "\"}";
    let code = that.playCode + "" + item.lid
    console.log("显示盘口的参数值:", obj);
    that.store.get(ConfigService.RATE_KEY + that.code + that.playABCD).then(function (d) {
      if (ToolService.isEmpty(d)) {
        let param = "{\"topcode\":\"" + that.code + "\"}";
        that.http.get(UrlService.LOTTERY_GETODDS, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(param) }).subscribe(res => {
          let data = res.json();
          ToolService.setEncrypt(data.encrypt);
          if (data.code == ConfigService.SUCCESS_CODE) {
            let tempRes = ToolService.aesDecodeToJson(data.data);
            that.store.set(ConfigService.RATE_KEY + that.code + that.playABCD, tempRes)
            let tempData = tempRes[code];
            that.lotNumData = [];
            that.tablebar = [];
            if (that.playCode == 'f3d_2dw' || that.playCode == 'pl3_2dw') {//福彩3d,体彩p3的二字定位
              if (item.lid == '55' || item.lid == '234') {//佰拾定位
                that.f3dLotData = tempData.item['Z1-Z2'];
                that.f3dLotData[0].mark = "Z1-Z2";
              } else if (item.lid == '56' || item.lid == '235') {//佰个定位
                that.f3dLotData = tempData.item['Z1-Z3'];
                that.f3dLotData[0].mark = "Z1-Z3";
              } else if (item.lid == '57' || item.lid == '236') {//拾个定位
                that.f3dLotData = tempData.item['Z2-Z3'];
                that.f3dLotData[0].mark = "Z2-Z3";
              }
              that.lotNumData = that.f3dLotData;
            } else {
              that.lotNumData = tempData.item;
            }
            that.tablebar = tempData.tablebar;
            if (mark <= that.tablebar.length - 1) {
              that.tablebar[mark]['isActive'] = true;
              $(".lot-tabbar").scrollLeft(120 * mark);
              $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
            }
          } else if (data.code == ConfigService.FAIL_CODE) {
            that.popWin.toast(data.message);
          } else if (data.code == ConfigService.LOGIN_CODE) {
            that.navCtrl.navigateForward("/login");
          }
        }, error => {
          console.log("error", error);
        });
        return;
      }
      //有倍率
      let tempData = d[code];
      that.lotNumData = [];
      that.tablebar = [];
      if (that.playCode == 'f3d_2dw' || that.playCode == 'pl3_2dw') {//福彩3d,体彩p3的二字定位
        if (item.lid == '55' || item.lid == '234') {//佰拾定位
          that.f3dLotData = tempData.item['Z1-Z2'];
          that.f3dLotData[0].mark = "Z1-Z2";
        } else if (item.lid == '56' || item.lid == '235') {//佰个定位
          that.f3dLotData = tempData.item['Z1-Z3'];
          that.f3dLotData[0].mark = "Z1-Z3";
        } else if (item.lid == '57' || item.lid == '236') {//拾个定位
          that.f3dLotData = tempData.item['Z2-Z3'];
          that.f3dLotData[0].mark = "Z2-Z3";
        }
        that.lotNumData = that.f3dLotData;
      } else {
        that.lotNumData = tempData.item;
      }
      that.tablebar = tempData.tablebar;
      if (mark <= that.tablebar.length - 1) {
        that.tablebar[mark]['isActive'] = true;
        $(".lot-tabbar").scrollLeft(120 * mark);
        $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
      }
      console.log("盘口", tempData);
    });
  }
  /**
   * 通过读取文件的形式价值数据
   * @param lid 
   * @param mark 
   */
  showLotBarDataBarkFile(lid, mark) {
    let that = this;
    let obj = "{\"code\":\"" + that.playCode + "\",\"lid\":\"" + lid + "\"}";
    let code = that.playCode + "" + lid
    console.log("显示盘口的参数值:", obj);
    that.store.get(ConfigService.RATE_KEY + that.code + that.playABCD).then(function (d) {
      if (ToolService.isEmpty(d)) {
        that.getJson(that.code, that.playABCD, function (fileData) {
          that.store.set(ConfigService.RATE_KEY + that.code + that.playABCD, fileData)
          let tempData = fileData[code];
          that.lotNumData = [];
          that.tablebar = [];
          that.lotNumData = tempData.item;
          that.tablebar = tempData.tablebar;
          if (mark <= that.tablebar.length - 1) {
            that.tablebar[mark]['isActive'] = true;
            $(".lot-tabbar").scrollLeft(120 * mark);
            $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
          }
          console.log("盘口", tempData);
        }, function () {
          that.popWin.toast("系统异常请重新登录");
        })
        return;
      }
      //有倍率
      let tempData = d[code];
      that.lotNumData = [];
      that.tablebar = [];
      that.lotNumData = tempData.item;
      that.tablebar = tempData.tablebar;
      if (mark <= that.tablebar.length - 1) {
        that.tablebar[mark]['isActive'] = true;
        $(".lot-tabbar").scrollLeft(120 * mark);
        $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
      }
      console.log("盘口", tempData);
    });
  }
  /**
   * @param lid 
   */
  showLotBarDataBark(lid, mark) {
    let that = this;
    that.lotNumData = [];
    that.tablebar = [];
    let obj = "{\"code\":\"" + that.playCode + "\",\"lid\":\"" + lid + "\"}";
    console.log("显示盘口的参数值:", obj);
    this.http.get(UrlService.USER_SHOWLOTS, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let tempData = ToolService.aesDecodeToJson(data.data);
        that.lotNumData = tempData.item;
        that.tablebar = tempData.tablebar;
        if (mark <= that.tablebar.length - 1) {
          that.tablebar[mark]['isActive'] = true;
          $(".lot-tabbar").scrollLeft(120 * mark);
          $(".lot-tabbar ul").css({ "width": that.tablebar.length * 120, "height": '50px' });
        }
        console.log("盘口", tempData);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 选中倍率的框
   * @param itemId 
   */
  selectLotCol(itemId) {
    if (this.disableBet) {
      this.popWin.toast("已经处于封盘中");
      return;
    }
    itemId=this.fillerItemId(itemId);
    if ($("#lot-id-" + itemId).hasClass('lot-select-col-active')) {
      $("#lot-id-" + itemId).removeClass("lot-select-col-active");
      this.selectLotNumber--;
    } else {
      $("#lot-id-" + itemId).addClass("lot-select-col-active");
      this.selectLotNumber++;
    }
    if (this.selectLotNumber > 0 && this.isFastFun()) {
      //this.clientHeight = ($(window).height() - 144) + "px";
      this.fastShowState = true;
      this.deailPresetVal();
    } else {
      this.fastShowState = false;
    }
    //计算投资总投资额
    this.calculateTotalBetMoney();
  }
  /**
   * 特殊的六合彩合肖和自选不中，福彩3d组选的逻辑,江苏快三红码和黑码组合
   * @param itemId 
   * @param type 
   * @param balls  有最大值和最小值 
   */
  selectSpecialLotCol(itemId, type, lottype?: String) {
    if (this.disableBet) {
      this.popWin.toast("已经处于封盘中");
      return;
    }
    itemId=this.fillerItemId(itemId);
    let minAndMax = [];//获取最新和最大选择值
    let zxItemID = "";
    if (!ToolService.isEmpty(this.f3dzx3_zx6 + "")) {
      let temp = this.f3dzx3_zx6;
      minAndMax = (temp.list[0].balls).match(/(\d{1,3})+(?:\.\d+)?/g);
      zxItemID = temp.list[0].item_id;
    }
    if (!ToolService.isEmpty(this.specialZmlmTypeLotColItem + "")) {
      let temp = this.specialZmlmTypeLotColItem;
      minAndMax = temp.balls.match(/(\d{1,3})+(?:\.\d+)?/g);
      zxItemID = temp.item_id;
    }
    if ($("#lot-id-" + itemId).hasClass('lot-select-col-active')) {
      $("#lot-id-" + itemId).removeClass("lot-select-col-active");
      this.selectLotNumber--;
    } else {
      if (type != 'f3d_zs3') {//非福彩3d的组选
        if (this.selectLotNumber >= 11) {
          this.popWin.toast("已经超出可选最大项目个数");
          return;
        }
      } else {
        if (this.selectLotNumber >= parseInt(minAndMax[1])) {
          this.popWin.toast("已经超出可选最大项目个数");
          return;
        }
      }
      $("#lot-id-" + itemId).addClass("lot-select-col-active");
      this.selectLotNumber++;
    }
    if (type == 'sxd') { //合肖
      if (this.isFastFun() && this.selectLotNumber >= 2) {
        this.fastShowState = true;
        this.deailPresetVal();
        this.getSpecialRate(lottype == 'lhc' ? ConfigService.LHC_SXD_ITEMID : (lottype == 'qlc' ? ConfigService.QLC_SXD_ITEMID : (lottype == 'mlc' ? ConfigService.MLC_SXD_ITEMID : ConfigService.TWD_SXD_ITEMID)));
      } else {
        this.fastShowState = false;
        this.specialRateVal = 0;
      }
    } else if (type == 'slx') {//自选不中
      if (this.isFastFun() && this.selectLotNumber >= 5) {
        this.fastShowState = true;
        this.deailPresetVal();
        this.getSpecialRate(lottype == 'lhc' ? ConfigService.LHC_SLX_ITEMID : (lottype == 'qlc' ? ConfigService.QLC_SLX_ITEMID : (lottype == 'mlc' ? ConfigService.MLC_SLX_ITEMID : ConfigService.TWD_SLX_ITEMID)));
      } else {
        this.fastShowState = false;
        this.specialRateVal = 0;
      }
    } else if (type == 'f3d_zs3' || type == 's3s_zs3_zs6' || type == 'ss8_zs3' || type == 'sgs_zs3') {
      if (this.isFastFun() && this.selectLotNumber >= parseInt(minAndMax[0])) {
        this.fastShowState = true;
        this.deailPresetVal();
        this.getSpecialRate(zxItemID);
      } else {
        this.fastShowState = false;
        this.specialRateVal = 0;
      }
    }
    //计算投资总投资额
    this.calculateTotalBetMoney();
  }
  /**
   * 获取特殊的赔率
   */
  getSpecialRate(itemid) {
    let that = this;
    this.selectLotNumberArr = [];
    let balls = "";
    $('.lot-select-col.lot-select-col-active').each(function (index) {
      let temp = $(this).find('.lot-select-val').attr("id");
      if (ToolService.isStringJSON(temp)) {
        that.selectLotNumberArr.push(JSON.parse(temp));
        balls += JSON.parse(temp).id + ",";
      }
    });
    balls = balls.substring(0, balls.length - 1);
    let obj = "{\"itemid\":\"" + itemid + "\",\"lotcode\":\"" + this.playCode + "\",\"balls\":\"" + balls + "\",\"region\":\"" + that.playABCD + "\"}";
    this.http.get(UrlService.LOTTERY_COMBRATE, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let res = ToolService.aesDecodeToJson(data.data);
        console.log(res);
        that.specialRateVal = res.rate;
      } else {
        that.specialRateVal = 0;
      }
    }, error => {
      that.specialRateVal = 0;
    });
  }
  /**
   * 连码选中类别
   * @param item 当前类别的对象
   * @param mark 下标
   */
  selectSpecialZmlmTypeLotCol(item, mark) {
    if (this.specialZmlmTypeLotColLock != mark) {
      this.onReset();
      this.resetVar();
      this.specialZmlmTypeLotColLock = mark;
      this.specialZmlmTypeLotColItem = item;
      $("ion-col.zmlm-type").removeClass("lot-select-zmlm-col-active");
      $("ion-col.zmlm-type").eq(mark).addClass("lot-select-zmlm-col-active");
      this.fastShowState = false;
    }

  }
  /**
   * 连码选中赔率
   * @param itemId 赔率的id
   */
  selectSpecialZmlmLotCol(itemId, markStr?: String) {
    if (this.disableBet) {
      this.popWin.toast("已经处于封盘中");
      return;
    }
    let tempBalls = (this.specialZmlmTypeLotColItem.balls).match(/(\d{1,3})+(?:\.\d+)?/g);
    let tid = this.specialZmlmTypeLotColItem.item_id;
    itemId=this.fillerItemId(itemId);
    if ($("#lot-id-" + itemId).hasClass('lot-select-col-active')) {
      $("#lot-id-" + itemId).removeClass("lot-select-col-active");
      this.selectZmlmNum--;
      delete this.selectZmlmArr[itemId];
    } else {
      if (markStr == 'zmlm') {//六合的连码固定只选择7个
        if (this.selectZmlmNum > 7) {
          this.popWin.toast("已经超出可选最大项目个数");
          return;
        }
      } else {
        if (this.selectZmlmNum > parseInt(tempBalls[1])) {
          this.popWin.toast("已经超出可选最大项目个数");
          return;
        }
      }

      this.selectZmlmArr[itemId] = itemId;
      this.selectZmlmNum++;
      $("#lot-id-" + itemId).addClass("lot-select-col-active");
    }
    //todo  选中个数和投资的逻辑处理
    if (this.selectZmlmNum - 1 >= tempBalls[0]) {//弹出底部的投资栏
      this.fastShowState = true;
      this.deailPresetVal();
      let tempRes = [];
      for (let item in this.selectZmlmArr) {
        tempRes.push(item);
      }
      let tempBetData = [];
      if (tempRes.length == tempBalls[0]) {
        tempBetData.push({ "id": tid, "balls": tempRes.join(',') });
      } else {
        let combineArr = ToolService.arrayCombine(tempRes, false, tempBalls[0]);
        for (let item in combineArr) {
          tempBetData.push({ "id": tid, "balls": combineArr[item] });
        }
      }
      this.selectLotNumber = tempBetData.length; //投注的注数
      this.calculateTotalBetMoney();//统计投资总额
      this.specialData = tempBetData;
      console.log("组合:", tempBetData);
    } else {//关闭投注栏
      this.fastShowState = false;
    }
  }

  isFastFun() {
    let isFast = localStorage.getItem("isFastMethod");
    if ((!ToolService.isEmpty(isFast) && isFast == '1' || ToolService.isEmpty(isFast))) {
      return true;
    } else {
      return false;
    }
  }
  /**
   * 福彩3d,体彩3d的二字和三字的处理
   * @param itemId 
   */
  selectF3dLotCol(itemId, playCode) {
    itemId=this.fillerItemId(itemId);
    if ($("#lot-id-" + itemId).hasClass("lot-select-col-active")) {
      $("#lot-id-" + itemId).removeClass("lot-select-col-active");
    } else {
      $("#lot-id-" + itemId).addClass("lot-select-col-active");
    }
    let idx0 = $("#lot-section-0 ion-col.lot-select-col-active").index();
    let idx1 = $("#lot-section-1 ion-col.lot-select-col-active").index();
    let res = [];//处理后存放的数组
    if (playCode == 'f3d_3dw' || playCode == 'pl3_3dw') {//三字
      let idx2 = $("#lot-section-2 ion-col.lot-select-col-active").index();
      if (idx0 >= 0 && idx1 >= 0 && idx2 >= 0) {
        this.fastShowState = true;
        this.deailPresetVal();
        let arr0 = this.getSelectF3dSelectSectionArr(0);
        let arr1 = this.getSelectF3dSelectSectionArr(1);
        let arr2 = this.getSelectF3dSelectSectionArr(2);
        let balls = this.getSelectF3dSelectSectionArr(0, false).join(",") + "," + this.getSelectF3dSelectSectionArr(1, false).join(",") + "," + this.getSelectF3dSelectSectionArr(2, false).join(",");
        this.get2dwOr3dwRate(balls);
        console.log("三字选中的balls", balls);
        res = ToolService.doExchange([arr0, arr1, arr2]);
      } else {
        this.fastShowState = false;
      }
    } else if (playCode == 'f3d_2dw' || playCode == 'pl3_2dw') {//二字
      if (idx0 >= 0 && idx1 >= 0) {
        this.fastShowState = true;
        this.deailPresetVal();
        let arr0 = this.getSelectF3dSelectSectionArr(0);
        let arr1 = this.getSelectF3dSelectSectionArr(1);
        let balls = this.getSelectF3dSelectSectionArr(0, false).join(",") + "," + this.getSelectF3dSelectSectionArr(1, false).join(",");
        this.get2dwOr3dwRate(balls);
        console.log("二字选中的balls", balls);
        res = ToolService.doExchange([arr0, arr1]);
      } else {
        this.fastShowState = false;
      }
    }
    this.selectLotNumber = res.length; //投注的注数
    this.calculateTotalBetMoney();//统计投资总额
    this.specialData = res;
  }

  getSelectF3dSelectSectionArr(index, isNum = true) {
    let arr = [];
    let obj = $("#lot-section-" + index + " ion-col.lot-select-col-active");
    if (isNum) {
      for (let i = 0; i < obj.length; i++) {
        let temp = obj.eq(i).find(".lot-select-val").attr("id");
        if (ToolService.isStringJSON(temp)) {
          arr.push((JSON.parse(temp)).name);
        }
      }
      return arr;
    } else {
      for (let i = 0; i < obj.length; i++) {
        let temp = obj.eq(i).find(".lot-select-val").attr("data-balls");
        arr.push(temp);
      }
      return arr;
    }
  }

  get2dwOr3dwRate(balls) {
    let that = this;
    let obj = "{\"itemid\":\"" + "" + "\",\"lotcode\":\"" + this.playCode + "\",\"balls\":\"" + balls + "\",\"region\":\"" + that.playABCD + "\"}";
    this.http.get(UrlService.LOTTERY_COMBRATE, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let res = ToolService.aesDecodeToJson(data.data);
        console.log(res);
        that.specialRateVal = res.rate;
      } else {
        that.specialRateVal = 0;
      }
    }, error => {
      that.specialRateVal = 0;
    });
  }
  /**
   * 计算投资总投资额，根据输入框
   */
  calculateTotalBetMoney() {
    if (this.isFastFun()) {
      if (this.playCode == 'lhc_sxd' || this.playCode == 'mlc_sxd' || this.playCode == 'twd_sxd' || this.playCode == 'qlc_sxd' || this.playCode == 'qlc_slx' || this.playCode == 'lhc_slx' || this.playCode == 'mlc_slx' || this.playCode == 'twd_slx') {
        this.betTotalMoney = 1 * this.betInputVal;
      } else {
        this.betTotalMoney = this.selectLotNumber * this.betInputVal;
      }
    }
    this.hideOrShowTab();
  }
  /**
   * 重置按钮
   */
  onReset() {
    $(".lot-select-col").removeClass('lot-select-col-active');
    this.selectLotNumber = 0;
    this.betTotalMoney = 0;
    this.fastShowState = false;
    $(".lot-mix-tabbar-kj").removeClass("active");
    this.specialRateVal = 0;
    this.mixRateSelect = [];
    this.mixType = [];
    this.mixBetArr = [];
    this.selectZmlmNum = 1;
    this.selectZmlmArr = [];
    this.hideOrShowTab();
    this.selectClItemArr.length = 0;
  }
  /**
   * 是否显示或隐藏公共底部的tab
   */
  hideOrShowTab() {
    if (this.fast && this.fastShowState) {
      this.isShowTab = false;
      this.deailPresetVal();
    } else {
      this.isShowTab = true;
    }
  }
  /**
   * 下注
   */
  async onBet(isModal: boolean = true, specialName?: string, specialData?: any) {
    if (this.disableBet) {
      this.popWin.toast("已经处于封盘中");
      return;
    }
    if (this.selectLotNumber == 0) {
      this.popWin.toast("请选择投资项目");
      return;
    }
    if (!ToolService.isEmpty(specialName) && !isModal && specialName == 'zmlm') {//特殊的投注方式
      this.betNet(specialData);
      this.onCloseMask();
      return;
    } else if (!ToolService.isEmpty(specialName) && !isModal && specialName == 'f3d_dw') {
      let res = [];
      let itemId = null;
      if (this.playCode == 'f3d_2dw' || this.playCode == 'pl3_2dw') {
        itemId = this.f3dLotData[0].mark;
      } else {
        itemId = ((this.f3dLotData[0].list)[0])['item_id'];
      }
      for (let item in specialData) {
        res.push({ "id": itemId, "balls": specialData[item].join(',') });
      }
      this.betNet(res);
      this.onCloseMask();
      return;
    }
    if ((this.code == 'pks' || this.code == 'pka' || this.code == 'yka' || this.code == 'sg8' || this.code == 'pt8' || this.code == 'pk8' || this.code == 'pkt' || this.code == 'sjs' || this.code == 'yjs' || this.code == 'ss8' || this.code == 'sgs' ||
      this.code == 'ssn' || this.code == 'xyssc' || this.code == 'ssc' || this.code == 'ssg' || this.code == 'klsf' || this.code == 'az8' || this.code == 'yz8' || this.code == 's10' || this.code == 'sgx' || this.code == 'sxg' || this.code == 'jsg' || this.code == 'sx5') && this.playCode == 'fast') {//快捷的快速投注  
      this.betMixBet(this.mixBetArr);
      //将数据给重置
      this.onCloseMask();
    } else {//非快捷的投注方式
      let that = this;
      this.selectLotNumberArr = [];
      $('.lot-select-col.lot-select-col-active').each(function (index) {
        let temp = $(this).find('.lot-select-val').attr("id");
        if (ToolService.isStringJSON(temp)) {
          that.selectLotNumberArr.push(JSON.parse(temp));
        }
      });
      if (isModal) {//第一种弹出modal的投注方式
        this.presentModal(this.selectLotNumberArr);
      } else {//直接处理数据
        if (specialName == 'slx_sxd') {//六合彩中的合肖和自选不中
          let tempBalls = [];
          for (let item in this.selectLotNumberArr) {
            tempBalls.push(this.selectLotNumberArr[item]['id']);
          }
          let item_id = this.playCode == 'lhc_sxd' ? ConfigService.LHC_SXD_ITEMID :
            (this.playCode == 'qlc_sxd' ? ConfigService.QLC_SXD_ITEMID :
              (this.playCode == 'mlc_sxd' ? ConfigService.MLC_SXD_ITEMID :
                (this.playCode == 'lhc_slx' ? ConfigService.LHC_SLX_ITEMID :
                  (this.playCode == 'mlc_slx' ? ConfigService.MLC_SLX_ITEMID : ConfigService.QLC_SLX_ITEMID))));
          if (this.playCode == 'qlc_slx') {
            item_id = ConfigService.QLC_SLX_ITEMID;
          }
          if (this.playCode == 'twd_sxd') {
            item_id = ConfigService.TWD_SXD_ITEMID;
          }
          if (this.playCode == 'twd_slx') {
            item_id = ConfigService.TWD_SLX_ITEMID;
          }
          this.betNet([{ "id": item_id, "balls": tempBalls.join(','), "rate": this.specialRateVal }]);
          return;
        } else if (specialName == 'f3d_zs') {
          let tempBalls = [];
          for (let item in this.selectLotNumberArr) {
            tempBalls.push(this.selectLotNumberArr[item]['id']);
          }
          if (!ToolService.isEmpty(this.f3dzx3_zx6 + "")) {
            let temp = this.f3dzx3_zx6;
            this.betNet([{ "id": temp.list[0].item_id, "balls": tempBalls.join(','), "rate": this.specialRateVal }]);
          }
          return;
        } else if (specialName == 'ss8_zs3' || specialName == 'sgs_zs3') {
          let tempBalls = [];
          for (let item in this.selectLotNumberArr) {
            tempBalls.push(this.selectLotNumberArr[item]['id']);
          }
          if (!ToolService.isEmpty(this.specialZmlmTypeLotColItem + "")) {
            let temp = this.specialZmlmTypeLotColItem;
            this.betNet([{ "id": temp.item_id, "balls": tempBalls.join(','), "rate": this.specialRateVal }]);
          }
          return;
        } else {
          this.betNet(this.selectLotNumberArr);
        }
        //将数据给重置
        this.onCloseMask();
      }
    }



  }


  async presentModal(params) {
    let that = this;
    const modal = await this.modalCtrl.create({
      showBackdrop: true,
      component: BetComponent,
      componentProps: { value: params, playCode: that.playCode, name: that.lotName, lotteryId: that.lotteryId, code: that.code }
    });
    await modal.present();
    this.onReset();
    //监听销毁的事件
    const { data } = await modal.onDidDismiss();
    if (data.result) {//更新更新的倍率
      that.updataLot();
    }
  }

  /**
   * 显示更多出奖结果
   */
  public isClickMore = true;
  onClickMore() {
    let obj = document.getElementById('res-contain');
    if (obj == null) {
      return;
    }
    if (this.isClickMore) {
      obj.style.height = "auto";
    } else {
      obj.style.height = this.resHeight;
    }
    this.isClickMore = !this.isClickMore;
  }
  /**
   * 从文件访问数据    17590-lhc-A.jsonp
   * @param code 标识码
   * @param ABCD ABCD盘
   * @param success 成功方法的回调
   * @param fail 失败方法的回调
   */
  getJson(code, ABCD, success, fail) {
    this.store.get(ConfigService.IS_LOGIN_STORE_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {
        this.navCtrl.navigateForward("/login");
        return;
      }
    });
    this.store.get(ConfigService.FUID_KEY).then((data) => {
      if (ToolService.isEmpty(data)) {
        this.navCtrl.navigateForward("/login");
        return;
      }
    });
    this.store.get(ConfigService.FUID_KEY).then((data) => {
      //拼接访问的的json文件名称
      let resUrl = ConfigService.SERVER_PATH + "/static/odds/" + data + "-" + code + "-" + ABCD + ".jsonp";
      $.ajax({ type: "get", url: resUrl, dataType: "jsonp", jsonp: "callback", jsonpCallback: "odds", success: function (data) { success(data); }, error: function () { fail(); } });
    });
  }
  /**
   * 主动更新盘口的数据信息
   */
  updataLot() {
    let that = this;
    let obj = "{\"topcode\":\"" + that.code + "\"}";
    this.http.get(UrlService.COMMON_SETINFO, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        //成功的逻辑
        let res = ToolService.aesDecodeToJson(data.data);
        that.store.get(ConfigService.RATE_KEY + that.code + that.playABCD).then(function (d) {
          if (!ToolService.isEmpty(d) && res.update) {
            //如果更新就更新数据
            that.store.remove(ConfigService.RATE_KEY + that.code + that.playABCD);
            that.showLotData(that.selectPlayItemData.item, that.selectPlayItemData.index, true);
            that.setPlayClickMark(that.selectPlayItemData.index);
          }
        });
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 重新设置出发每间隔20s加载赔率
   */
  updataLotCount() {
    let that = this;
    that.clearTimer(that.tempTimer03Arr);
    that.tempTimer03 = setInterval(function () {
      that.updataLot();
    }, 20000);
    that.tempTimer03Arr.push(that.tempTimer03);
  }

  /**
   * 获取未结算和今日余额
   */
  getMoney() {
    let that = this;
    this.http.get(UrlService.USER_FINDCREDIT, { "callback": "JSONP_CALLBACK" }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let res = ToolService.aesDecodeToJson(data.data);
        that.moneyObj = res;
        console.log("--金额===", res);
        that.store.set(ConfigService.MONEY_KEY, res);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }
  /**
   * 显示未结算和今日余额
   */
  showMoney() {
    this.isMoney = !this.isMoney;
    this.isRegion = false;
    this.hideDownMenu();
  }

  hideRegionAndMoney() {
    this.isMoney = false;
    this.isRegion = false;
  }
  /**
   * 输入金额去计算值
   */
  onSetBet() {
    let num = this.getFastInputVal("fast-bet-input-text");
    this.betInputVal = num;
    if (this.playCode == 'lhc_sxd' || this.playCode == 'mlc_sxd' || this.playCode == 'twd_sxd' || this.playCode == 'qlc_sxd' || this.playCode == 'qlc_slx' || this.playCode == 'lhc_slx' || this.playCode == 'mlc_slx' || this.playCode == 'twd_slx') {
      this.betTotalMoney = num;
    } else {
      this.betTotalMoney = this.selectLotNumber * num;
    }
  }
  /**
   * 将数据进行投注操作
   */
  async betNet(data) {
    let that = this;
    let num = this.getFastInputVal("fast-bet-input-text");
    for (let i = 0; i < data.length; i++) {
      data[i]['cash'] = num;
    }
    let obj = "{\"lotcode\":\"" + that.playCode + "\",\"rows\":" + JSON.stringify(data) + "}";
    console.log("下注的参数:", obj);
    const loading = await this.loadingCtrl.create({ message: "提交中...", duration: 10000000, mode: 'ios' });
    await loading.present();

    let token = $("app-root").attr("token");
    let sessid = $("app-root").attr("sessid");
    let uid = $("app-root").attr("uid");
    let encrypt = (!ToolService.isEmpty($("app-root").attr("encrypt")) && $("app-root").attr("encrypt") == '1') ? 1 : 0;
    let baseParam;
    if (ToolService.isEmpty(sessid)) {
      baseParam = { "token": ToolService.isEmpty(token) ? "" : token, "data": ToolService.aesEncode(obj), "tross": "createorder", "encrypt": encrypt, "uid": uid, "v": ConfigService.APP_VERSION };
    } else {
      baseParam = { "token": ToolService.isEmpty(token) ? "" : token, "sessid": sessid, "data": ToolService.aesEncode(obj), "tross": "createorder", "encrypt": encrypt, "uid": uid, "v": ConfigService.APP_VERSION };
    }
    console.log("------ajax:", baseParam);
    var api = ConfigService.SERVER_PATH + UrlService.LOTTERY_CREATEORDER;
    $.ajax({
      url: api, data: baseParam, dataType: 'json', success: function (res) {
        let data = res
        loading.dismiss();
        if (data.code == ConfigService.SUCCESS_CODE) {
          //成功的逻辑
          let tempData = ToolService.aesDecodeToJson(data.data);
          that.showBetWin();
          that.betSuccessObj = tempData;
          that.getMoney();
          console.log("成功后的输出结果:", tempData);
        } else if (data.code == ConfigService.FAIL_CODE) {
          that.popWin.toast(data.message);
        } else if (data.code == ConfigService.LOGIN_CODE) {
          that.navCtrl.navigateForward("/login");
        } else if (data.code == ConfigService.BET_CHANGE_RATE) {
          that.popWin.toast(data.message);
        } else {
          that.popWin.toast(data.message);
        }
      }, complete: function () {
        loading.dismiss();
      }, type: 'POST'
    });

  }
  /**
   * 快捷的混合投注操作
   */
  async betMixBet(data) {
    let that = this;
    let num = this.getFastInputVal("fast-bet-input-text");
    for (let i = 0; i < data.length; i++) {
      data[i]['cash'] = num;
    }
    let obj = "{\"rows\":" + JSON.stringify(data) + "}";
    console.log("混合快捷投注的参数:", obj);
    const loading = await this.loadingCtrl.create({ message: "提交中...", duration: 10000, mode: 'ios' });
    await loading.present();
    this.popWin.loading("", "bubbles", 1000);
    this.http.get(UrlService.LOTTERY_FASTORDER, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      loading.dismiss();
      if (data.code == ConfigService.SUCCESS_CODE) {
        //成功的逻辑
        let tempData = ToolService.aesDecodeToJson(data.data);
        that.showBetWin();
        that.betSuccessObj = tempData;
        that.getMoney();
        // console.log("成功后的输出结果:", tempData);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      } else if (data.code == ConfigService.BET_CHANGE_RATE) {
        that.popWin.toast(data.message);
      } else {
        that.popWin.toast(data.message);
      }
    }, error => {
      console.log("error", error);
      loading.dismiss();
    });
  }
  /**
   * 点击确定去进行下注的页面
   */
  onFastSubmit() {
    if (this.betInputVal <= 0) {
      this.popWin.alert("请输入投注额");
      return;
    }
    if (this.isCl) {
      this.onCLBet();
    } else {
      //投注数据
      if (this.playCode == 'qlc_zmlm' || this.playCode == 'lhc_zmlm' || this.playCode == 'mlc_zmlm' || this.playCode == 'twd_zmlm' || this.playCode == 'ssg_rx' || this.playCode == 'sxg_rx' || this.playCode == 'jsg_rx' || this.playCode == 'sx5_rx' || this.playCode == 'klsf_rx' || this.playCode == 'az8_rx' || this.playCode == 'yz8_rx' || this.playCode == 's10_rx' || this.playCode == 'stj_rx' || this.playCode == 'qlc_ddb' || this.playCode == 'lhc_ddb' || this.playCode == 'mlc_ddb' || this.playCode == 'twd_ddb' || this.playCode == 'stj_rx') { //连码,六合彩的连肖连尾的特殊投注 
        this.onBet(false, 'zmlm', this.specialData);
      } else if (this.playCode == 'lhc_sxd' || this.playCode == 'mlc_sxd' || this.playCode == 'twd_sxd' || this.playCode == 'qlc_sxd' || this.playCode == 'lhc_slx' || this.playCode == 'mlc_slx' || this.playCode == 'twd_slx' || this.playCode == 'qlc_slx') { //六合彩合肖和自选不中的投注
        this.onBet(false, "slx_sxd");
      } else if (this.playCode == 'f3d_2dw' || this.playCode == 'f3d_3dw' || this.playCode == 'pl3_2dw' || this.playCode == 'pl3_3dw') {//福彩3d,体彩3d的二字和三字
        this.onBet(false, 'f3d_dw', this.specialData);
      } else if (this.playCode == 'f3d_zs3' || this.playCode == 'f3d_zs6' || this.playCode == 'pl3_zs3' || this.playCode == 'pl3_zs6') {//福彩3d的组选,
        this.onBet(false, 'f3d_zs');
      } else if (this.playCode == 'ss8_zs3' || this.playCode == 'sgs_zs3') {//ss8_zs3极速时时彩组选三
        this.onBet(false, 'ss8_zs3');
      } else {
        this.onBet(false);
      }
    }
    this.setPresetVal();
  }
  /**
   * 关闭蒙版的窗口
   */
  onCloseMask() {
    this.isMarkWin = false;
    this.onReset();
  }
  isSetFastBetMoney() {
    let isFastMoney = localStorage.getItem("setfastMoney");
    if ((!ToolService.isEmpty(isFastMoney) && isFastMoney == '1' || ToolService.isEmpty(isFastMoney))) {
      return true;
    } else {
      return false;
    }
  }
  /**
   * 设置投资的金额的数据
   */
  setPresetVal() {
    let checkV = $('input[name="fast-checkbox"]:checked').val();
    if (ToolService.isEmpty(checkV)) {//取消预设
      this.store.set("preset", { "preset": "0", "value": "" });
      this.betInputVal = 0;
      this.betMoney = "";
      $("#fast-bet-input-text").val("");
    } else {//预设
      this.store.set("preset", { "preset": "1", "value": this.betInputVal });
    }
  }
  /**
   * 复原投资的金额的数据
   */
  async deailPresetVal() {
    let that = this;
    let res;
    await this.store.get("preset").then(function (tempRes) {
      res = tempRes;
    });
    if (ToolService.isEmpty(res)) {
      return;
    }
    if (res.preset == "1" || res.preset == 1) {
      $("input[name='fast-checkbox']").attr("checked", "checked");
      if (!ToolService.isEmpty(res.value) && res.value != 0 && res.value != "0") {
        if (ToolService.isEmpty($("#fast-bet-input-text").val())) {
          that.betInputVal = res.value;
          $("#fast-bet-input-text").val(res.value);
        }
      }
    } else {
      if (ToolService.isEmpty($("#fast-bet-input-text").val()) && ToolService.isEmpty(res.value)) {
        this.betTotalMoney = 0;
        $("#fast-bet-input-text").val("")
      }
    }

    console.log("这里的地方:", $("#fast-bet-input-text").val());
  }
  /**
   * 编辑预设金额弹窗
   */
  onEditShowWin() {
    this.isMarkWin = true;
    this.isResOrFastmoney = false;
  }
  /**
   * 投注成功后数据的回显弹窗
   */
  showBetWin() {
    this.isMarkWin = true;
    this.isResOrFastmoney = true;
  }
  getFastInputVal(objStr) {
    let o = $("#" + objStr).val() + "";
    return ToolService.isNumber(parseInt(o)) ? parseInt(o) : 0;
  }
  /**
   * 设置快捷金额的确定按钮
   */
  onSetFastMoneySubmit() {
    if (this.getFastInputVal("preset_0") <= 0 || this.getFastInputVal("preset_1") <= 0 || this.getFastInputVal("preset_2") <= 0 || this.getFastInputVal("preset_3") <= 0 || this.getFastInputVal("preset_4") <= 0) {
      this.popWin.toast("请填写设置金额");
      return;
    }
    let redioVal = $('input[name="radio"]:checked').val();
    if (ToolService.isEmpty(redioVal)) {
      this.popWin.toast("请选择启用还是停用");
      return;
    }
    if (redioVal == 1) {//启用
      this.fastMoneyList = { "o": this.getFastInputVal("preset_0"), "t": this.getFastInputVal("preset_1"), "th": this.getFastInputVal("preset_2"), "f": this.getFastInputVal("preset_3"), "fi": this.getFastInputVal("preset_4") };
      localStorage.setItem("fastMoneyList", JSON.stringify(this.fastMoneyList));
    } else {//停用
      this.fastMoneyList = this.fastDefaultMoneyList;
      localStorage.removeItem("fastMoneyList");
    }
    this.isMarkWin = false;
  }
  /**
   * 选择到快捷金额上面
   */
  onSelectFastMoney(val) {
    $("#fast-bet-input-text").val(val);
    this.onSetBet();
  }

  /**
   * 特殊的六合彩和极速六合的特殊连码的结果处理
   * @param arr 
   */
  specialZmlm(arr) {
    function isCN(str) {
      if (escape(str).indexOf("%u") < 0) {
        return false;
      } else {
        return true;
      }
    }
    function objSort(arr) {
      arr.sort(function (a, b) {
        var f = a.rate;
        if (f === undefined || f === null || f === '' || f === ' ' || f === '　' || isCN(f)) {
          return -1
        }
      });
      return arr;
    }
    function numReplaceStr(targetData, keyName) {
      var tempArr = (targetData[keyName]).split('/');
      if (tempArr.length == 2) {
        var arr0 = tempArr[0].match(/\d+(.\d+)?/g);
        var arr1 = tempArr[1].match(/\d+(.\d+)?/g);
        var cn0 = tempArr[0].replace(/\d+(.\d+)?/g, '');
        var cn1 = tempArr[1].replace(/\d+(.\d+)?/g, '');
        targetData[keyName] = cn0 + '<span style="color:#ff4a4a">' + arr0 + '</span>' + '/' + cn1 + '<span  style="color:#ff4a4a">' + arr1 + '</span>';
        targetData['resRate'] = arr0 + '/' + arr1
      } else {
        targetData['resRate'] = targetData[keyName];
      }
    }
    var res = objSort(arr);
    for (var item in res) {
      numReplaceStr(res[item], 'rate')
    }
    return res;
  }



  /**
   * 折叠盘口的大的数据
   */
  foldName(index) {
    $("#fold-grid-" + index).fadeToggle("fast", function () {
      if ($(this).is(":visible")) {
        $("#fold-div-" + index).removeClass("fold-div-bottom").find("i").removeClass("ion-ios-down-trangle").addClass("ion-ios-down-trangle-copy");
      } else {
        $("#fold-div-" + index).addClass("fold-div-bottom").find("i").removeClass("ion-ios-down-trangle-copy").addClass("ion-ios-down-trangle");
      }
    });
  }
  /** 
   * 加载开奖结果20条数据
   */
  lot20Data(topcode, refreshobj?: IonRefresher) {
    let that = this;
    let obj = "{\"topcode\":\"" + topcode + "\",\"page\":\"1\",\"pageSize\":\"20\"}";
    this.http.get(UrlService.LOTTERY_INDEX, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      if (!ToolService.isEmpty(refreshobj)) {
        refreshobj.complete();
      }
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let tt = ToolService.aesDecodeToJson(temp);
        if (tt.data.length == 0) {
          that.listData = [];
          that.tabarData = { "cycleid": "", "sdate": "", "balls": "", "sum": "", "nn": "", "dx": "", "ds": "", "gylh": "", "show": tt.tabar.show, "tm": "", "zh": "","bsl":"" };
          that.isRes = false;
          return;
        }
        that.isRes = true;
        that.tabarData = tt.tabar;
        that.listData = tt.data;
        that.initState();
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
      if (!ToolService.isEmpty(refreshobj)) {
        refreshobj.complete();
      }
    });
  }

  onSelectType(type: string) {// balls号码,dx大小,ds单双,gylh冠亚/龙虎,sum总和,nn牛牛，
    this.showStateFun(type);
  }
  showStateFun(type: string) {
    switch (type) {
      case 'balls': {
        this.showStateData = { "balls": true, "sum": false, "nn": false, "dx": false, "ds": false, "gylh": false, "tm": false, "zh": false,"bsl":false };
        break;
      }
      case 'dx': {
        this.showStateData = { "balls": false, "sum": false, "nn": false, "dx": true, "ds": false, "gylh": false, "tm": false, "zh": false,"bsl":false };
        break;
      }
      case 'ds': {
        this.showStateData = { "balls": false, "sum": false, "nn": false, "dx": false, "ds": true, "gylh": false, "tm": false, "zh": false,"bsl":false };
        break;
      }
      case 'gylh': {
        this.showStateData = { "balls": false, "sum": false, "nn": false, "dx": false, "ds": false, "gylh": true, "tm": false, "zh": false,"bsl":false };
        break;
      }
      case 'sum': {
        this.showStateData = { "balls": false, "sum": true, "nn": false, "dx": false, "ds": false, "gylh": false, "tm": false, "zh": false,"bsl":false };
        break;
      }
      case 'nn': {
        this.showStateData = { "balls": false, "sum": false, "nn": true, "dx": false, "ds": false, "gylh": false, "tm": false, "zh": false,"bsl":false };
        break;
      }
      case 'tm': {
        this.showStateData = { "balls": false, "sum": false, "nn": false, "dx": false, "ds": false, "gylh": false, "tm": true, "zh": false,"bsl":false};
        break;
      }
      case 'zh': {
        this.showStateData = { "balls": false, "sum": false, "nn": false, "dx": false, "ds": false, "gylh": false, "tm": false, "zh": true,"bsl":false };
        break;
      }
      case 'bsl': {
        this.showStateData = { "balls": false, "sum": false, "nn": false, "dx": false, "ds": false, "gylh": false, "tm": false, "zh": false,"bsl":true };
        break;
      }
    }
  }

  initState() {
    if (this.tabarData.balls) {
      this.showStateFun("balls");
      return;
    } else if (this.tabarData.dx) {
      this.showStateFun("dx");
      return;
    } else if (this.tabarData.ds) {
      this.showStateFun("ds");
      return;
    }
  }

  refresh20(event) {
    this.lot20Data(this.code, event.target);
  }
  /**
   * 最新20期的底部加载更多开奖结果直接跳转
   */
  loadMoreLotter() {
    this.navCtrl.navigateRoot("/tabs/lottery");
    this.eventS.publish("selectCommonTab4", 4);
  }
  /**
   * 设置选择的玩法的标记
   * @param mark 选中的第几个玩法
   */
  setPlayClickMark(mark) {
    $("app-root").attr("playMark", mark)
  }

  //菜单向下
  async showDownMenu() {
    this.hideRegionAndMoney();//隐藏盘口或金额的下拉
    if (this.isShowDownMenu()) {//显示就隐藏同时清除计时器
      $(".down-menu-mark").css("display", "none");
      $(".down-menu-icon").removeClass("ion-ios-fanhui1-up").addClass("ion-ios-fanhui1-down");
      this.clearDownMenuTime();
      return;
    }
    let lotMenu: any[];
    await this.store.get(ConfigService.LOTTER_MENU).then((res) => {
      lotMenu = res;
    });
    this.lotMenuArr = lotMenu;
    if (ToolService.isEmpty(lotMenu)) {//没有菜单就不处理下面的业务逻辑
      return;
    }
    console.log("下拉的菜单:", lotMenu);
    //时间的处理
    this.timeNet();
    $(".down-menu-mark").css("display", "block");
    $(".down-menu-icon").removeClass("ion-ios-fanhui1-down").addClass("ion-ios-fanhui1-up")
  }
  /**
   * 禁止冒泡事件
   * @param event 
   */
  onForbidCloseFun(event) {
    event.stopPropagation();
  }
  /**
   * 选择下拉菜单的一个数据显示
   * @param code 
   * @param name 
   * @param lotteryId 
   */
  onSelectDownMenuItem(code, name, lotteryId) {
    this.hideDownMenu();
    if (this.code == code) {
      return;
    }
    console.log("下拉菜单点击切换|code:" + code + "-name:" + name + "-lotteryId:" + lotteryId);
    this.eventS.publish("menuEvent", code, name, lotteryId);
  }
  timeNet() {
    let that = this;
    this.http.get(UrlService.USER_TIME, { "callback": "JSONP_CALLBACK" }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let tt = ToolService.aesDecodeToJson(temp);
        if (ToolService.isEmpty(tt.times)) {
          return;
        }
        for (let item in tt.times) {
          let tempTime = tt.times[item] - tt.now;
          if (item == 'lhc' || item == 'mlc' || item == 'twd' || item == 'f3d' || item == 'pl3') {
            $("#menu-code-" + item).html(ToolService.formateTime(tempTime));
          } else {
            $("#menu-code-" + item).html(ToolService.formateTime(tempTime, true));
          }
          $("#menu-code-" + item).attr("data-time", tempTime);
        }
        that.countdownFun();
      } else if (data.code == ConfigService.FAIL_CODE) {
        // this.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        this.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  countdownFun() {
    let that = this;
    this.clearDownMenuTime();
    let timeArr = [];
    let obj = $(".d--m-c-son-time");
    obj.each(function (index) {
      let tempObj = obj.eq(index);
      let temp = parseInt(tempObj.attr("data-time"));
      if (tempObj.html() != "已封盘") {
        obj.eq(index).removeClass("red");
      }
      if (ToolService.isNumber(temp) && tempObj.html() != "已封盘") {
        let timer = setInterval(function () {
          if (temp <= 1) {
            obj.eq(index).html("已封盘");
            obj.eq(index).addClass("red");
            obj.eq(index).removeAttr("data-time");
            return;
          }
          temp--;
          obj.eq(index).attr("data-time", temp);
          obj.eq(index).removeClass("red");
          if (ToolService.isNumber("" + temp)) {
            if (obj.eq(index).attr("data-code") == 'lhc' || obj.eq(index).attr("data-code") == 'mlc' || obj.eq(index).attr("data-code") == 'twd' || obj.eq(index).attr("data-code") == 'f3d' || obj.eq(index).attr("data-code") == 'pl3') {
              tempObj.html(ToolService.formateTime(temp));
            } else {
              tempObj.html(ToolService.formateTime(temp, true));
            }

          }
        }, 1000);
        timeArr.push(timer);
      }
    });
    let tempRefreshTimeNet = setTimeout(function () {
      if (that.isShowDownMenu()) {
        that.timeNet();
      }
      that.lotMenuTimeTen.push(tempRefreshTimeNet);
      clearTimeout(tempRefreshTimeNet);
    }, 10000);
    this.lotMenuTimerArr = timeArr;

  }
  /**
   * 隐藏下拉下拉下来的菜单
   */
  hideDownMenu() {
    if (this.isShowDownMenu()) {
      $(".down-menu-mark").css("display", "none");
      $(".down-menu-icon").removeClass("ion-ios-fanhui1-up").addClass("ion-ios-fanhui1-down");
      //清除计时器
      this.clearDownMenuTime();
    }
  }
  isShowDownMenu() {
    if ($(".down-menu-mark").is(":visible") && $(".down-menu-icon").hasClass("ion-ios-fanhui1-up")) {
      return true;
    }
    return false;
  }
  /**
   * 清除下拉菜单的计时器
   */
  clearDownMenuTime() {
    this.clearTimer(this.lotMenuTimerArr);
    this.lotMenuTimerArr = [];
    this.clearTimer(this.lotMenuTimeTen, true);
    this.lotMenuTimeTen = [];
  }


  /////长龙相关的数据
  getClData(win_times = '6') {
    let that = this;
    that.clearPeriodTimer();
    that.clearCLTenTimer();
    let obj = "{\"win_times\":\"" + win_times + "\"}";
    this.http.get(UrlService.LOTSGAM_GETCHANGLONG, { "callback": "JSONP_CALLBACK", "data": ToolService.aesEncode(obj) }).subscribe(res => {
      let data = res.json();
      ToolService.setEncrypt(data.encrypt);
      if (data.code == ConfigService.SUCCESS_CODE) {
        let temp = data.data;
        let tt = ToolService.aesDecodeToJson(temp);
        if (!ToolService.isEmpty(tt)) {
          that.clArr = tt;
          let tempTimer = setTimeout(function () {
            that.periodTimer();//计时器的的处理
            clearTimeout(tempTimer);
          }, 10);
          if (that.isCl) {
            let tenTimer = setTimeout(function () {
              that.getClData(that.periodValue);
              clearTimeout(tenTimer);
            }, 10000);
            that.clTenTimerArr.push(tenTimer);
          } else {
            that.clearCLTenTimer();
          }
        } else {
          that.clArr = [];
        }
        console.log("获取长龙的数据:", tt);
      } else if (data.code == ConfigService.FAIL_CODE) {
        that.popWin.toast(data.message);
      } else if (data.code == ConfigService.LOGIN_CODE) {
        that.navCtrl.navigateForward("/login");
      }
    }, error => {
      console.log("error", error);
    });
  }

  widthVal(val) {
    return val * 100 + "%";
  }

  selectDrawItem(itemID) {
    this.selectCLItemPushArr(this.selectClItemArr, itemID);
    console.log("选中长龙的itemID:" + itemID + "--所有长龙的数据:" + this.selectClItemArr);
    if ($("#period-item-content-target-" + itemID).hasClass("select")) {
      $("#period-item-content-target-" + itemID).removeClass("select");
      this.selectLotNumber--;
    } else {
      $("#period-item-content-target-" + itemID).addClass("select");
      this.selectLotNumber++;
    }
    if (this.selectLotNumber > 0 && this.isFastFun()) {
      this.fastShowState = true;
      this.deailPresetVal();
    } else {
      this.fastShowState = false;
    }
    //计算投资总投资额
    this.calculateTotalBetMoney();
  }
  /**
   * 长龙的投注
   */
  async onCLBet() {
    let that = this;
    this.selectLotNumberArr = [];
    $('.period-item-content-target.select').each(function (index) {
      let temp = $(this).find(".period-item-content-target-value").attr("id");
      if (ToolService.isStringJSON(temp)) {
        that.selectLotNumberArr.push(JSON.parse(temp));
      }
    });
    let num = this.getFastInputVal("fast-bet-input-text");
    for (let i = 0; i < this.selectLotNumberArr.length; i++) {
      this.selectLotNumberArr[i]['cash'] = num;
    }
    let obj = "{\"rows\":" + JSON.stringify(this.selectLotNumberArr) + "}";
    console.log("下注的参数:", obj);
    const loading = await this.loadingCtrl.create({ message: "提交中...", duration: 100000000000, mode: 'ios' });
    await loading.present();
    let token = $("app-root").attr("token");
    let sessid = $("app-root").attr("sessid");
    let uid = $("app-root").attr("uid");
    let encrypt = (!ToolService.isEmpty($("app-root").attr("encrypt")) && $("app-root").attr("encrypt") == '1') ? 1 : 0;
    let baseParam;
    if (ToolService.isEmpty(sessid)) {
      baseParam = { "token": ToolService.isEmpty(token) ? "" : token, "data": ToolService.aesEncode(obj), "tross": "createorder", "encrypt": encrypt, "uid": uid, "v": ConfigService.APP_VERSION };
    } else {
      baseParam = { "token": ToolService.isEmpty(token) ? "" : token, "sessid": sessid, "data": ToolService.aesEncode(obj), "tross": "createorder", "encrypt": encrypt, "uid": uid, "v": ConfigService.APP_VERSION };
    }
    console.log("------ajax:", baseParam);
    var api = ConfigService.SERVER_PATH + UrlService.LOTTERY_CHANGLONGCREATEORDER;
    $.ajax({
      url: api, data: baseParam, dataType: 'json', success: function (res) {
        let data = res
        loading.dismiss();
        if (data.code == ConfigService.SUCCESS_CODE) {
          //成功的逻辑
          let tempData = ToolService.aesDecodeToJson(data.data);
          that.showBetWin();
          that.betSuccessObj = tempData;
          that.getMoney();
          console.log("成功后的输出结果:", tempData);
        } else if (data.code == ConfigService.FAIL_CODE) {
          that.popWin.toast(data.message);
        } else if (data.code == ConfigService.LOGIN_CODE) {
          that.navCtrl.navigateForward("/login");
        } else if (data.code == ConfigService.BET_CHANGE_RATE) {
          that.popWin.toast(data.message);
        } else {
          that.popWin.toast(data.message);
        }
      }, complete: function () {
        loading.dismiss();
      }, type: 'POST'
    });
  }
  /**
   * 选中开奖期数
   */
  selectPeriodValue() {
    if (this.periodValue != this.periodPreValue) {
      this.periodPreValue = this.periodValue;
      this.resetSelectClItem();
      //执行
      this.getClData(this.periodValue);
    }
  }

  /**
   * 开奖的计时器
   */
  periodTimer() {
    let that = this;
    that.clearPeriodTimer();
    let fpIndex = [];
    $(".draw-timer-d").each(function (index) {
      let tempVal = parseInt($(".draw-timer-d").eq(index).attr("id")); //距离封盘的时间
      let tempOpenTime = parseInt($(".draw-timer-d").eq(index).attr("data-open")); //距离开奖的时间
      let tempItemObj = $(".period-item-content-t:eq(" + index + ") .period-item-content-target");
      if (tempVal <= 0) {
        $(".draw-timer-d").eq(index).html("--");
        tempItemObj.each(function (index2) {
          if (that.isExitVal(that.selectClItemArr, tempItemObj.eq(index2).attr("item-id"))) {
            if (tempItemObj.eq(index2).hasClass("select")) {
              tempItemObj.eq(index2).removeClass("select");
              that.selectCLItemPushArr(that.selectClItemArr, tempItemObj.eq(index2).attr("item-id"));
            }
          }
        });
        fpIndex = that.pushOnlyArr(fpIndex, index);
        //重置投注界面的数据
        that.resetCalcCLSelectNum();
        if (tempOpenTime >= 0) { //封盘还未开奖就显示蒙蔽
          $(".period-item-mark").eq(index).addClass("close");
        } else {//封盘已经开奖就隐藏,10s自动刷新数据后自动给隐藏
          $(".period-item").eq(index).css("display", "none");
        }
      } else {
        $(".draw-timer-d").eq(index).html(ToolService.formateTime($(".draw-timer-d").eq(index).attr("id"), true));
      }

      let tempTime = setInterval(function () {
        if ($(".period-item").eq(index).is(":visible")) {
          tempVal--;
          tempOpenTime--;
          if (tempVal <= 0) {
            $(".draw-timer-d").eq(index).html("--");
            if (!that.isExitVal(fpIndex, index)) {//将封盘的被选中的item给移除掉
              tempItemObj.each(function (index2) {
                if (that.isExitVal(that.selectClItemArr, tempItemObj.eq(index2).attr("item-id"))) {
                  if (tempItemObj.eq(index2).hasClass("select")) {
                    tempItemObj.eq(index2).removeClass("select");
                    that.selectCLItemPushArr(that.selectClItemArr, tempItemObj.eq(index2).attr("item-id"));
                  }
                }
              });
              fpIndex = that.pushOnlyArr(fpIndex, index);
              //重置投注界面的数据
              that.resetCalcCLSelectNum();
            }
            if (tempOpenTime >= 0) { //封盘还未开奖就显示蒙蔽
              $(".period-item-mark").eq(index).addClass("close");
            } else {//封盘已经开奖就隐藏,10s自动刷新数据后自动给隐藏
              $(".period-item").eq(index).css("display", "none");
            }
          } else {
            $(".draw-timer-d").eq(index).html(ToolService.formateTime($(".draw-timer-d").eq(index).attr("id"), true));
          }
          $(".draw-timer-d").eq(index).attr("id", tempVal);
          $(".draw-timer-d").eq(index).attr("data-open", tempOpenTime);
        }
      }, 1000);
      that.periodTimerArr.push(tempTime);
    });
  }
  /**
   * 长龙有封盘充值选中的多少注单的数据
   */
  resetCalcCLSelectNum() {
    this.selectLotNumber = this.selectClItemArr.length;
    if (this.selectLotNumber > 0 && this.isFastFun()) {
      this.fastShowState = true;
      this.deailPresetVal();
    } else {
      this.fastShowState = false;
    }
    //计算投资总投资额
    this.calculateTotalBetMoney();
  }
  /**
   * 清除长龙倒计时的时间
   */
  clearPeriodTimer() {
    this.clearTimer(this.periodTimerArr);
    this.periodTimerArr = [];
  }
  /**
   * 清除长龙间隔10s加载的时间
   */
  clearCLTenTimer() {
    this.clearTimer(this.clTenTimerArr, true);
    this.clTenTimerArr = [];
  }
  /**
   * 手动刷新长龙的数据
   */
  refreshCL() {
    this.getClData(this.periodValue);
    this.resetSelectClItem();
  }
  /**
   * 重置长龙的选中
   */
  resetSelectClItem() {
    this.selectClItemArr.length = 0;
    this.resetCalcCLSelectNum();
  }
  /**
   * 存储唯一的数组值
   * @param arr 是数组
   * @param val 是值
   */
  pushOnlyArr(arr, val) {
    if (arr.indexOf(val) == -1) {
      arr.push(val);
    }
    return arr;
  }
  /**
   * 判断数组中是否存在制定的值
   * @param arr 目标数组
   * @param val 目标的值
   */
  isExitVal(arr, val) {
    let isExit = false;
    if (arr.indexOf(val) > -1) {
      isExit = true;
    }
    return isExit;
  }
  /**
   * 如果存在值就删除，否则新增加
   * @param arr 目标数组
   * @param val 需要处理的值
   */
  selectCLItemPushArr(arr, val) {
    var idx = arr.indexOf(val);
    if (idx > -1) {
      arr.splice(idx, 1);
    } else {
      arr.push(val);
    }
  }

  pkPercent(val) {
    return (parseFloat(val) * 100).toFixed(2);
  }
  
  fillerBsl(val) {
    if (val === "前(多)" || val === "单(多)") {
      return "qdd";
    } else if (val === "单双(和)" || val === "前后(和)") {
      return "qdh";
    } else if (val === "双(多)" || val === "后(多)") {
      return "shd";
    } else if (val === "金") {
      return "jin";
    } else if (val === "木") {
      return "mu";
    } else if (val === "水") {
      return "shui";
    } else if (val === "火") {
      return "huo";
    } else if (val === "土") {
      return "tu";
    }
  }

  fillerItemId(val){
    let res= parseInt(val);
    if(isNaN(res)){
        return val;
    }else{
      return res;
    }
  }






}
